And I simply want to take the contents from each tag and put it in a new row in my table view. Unfortunately I have no clue…how to parse this RSS file.
An RSS fie is just a text file. As such you can use standard text parsing methods like text item delimiters, grep, and awk. Here’s one method…
-- get the text from the rss file
set f to (path to desktop as text) & "a.rss"
set theText to read file f
-- remove all of the text before the first <item> tag because you don't want titles from that section
set text item delimiters to "<item>"
set theGoodPart to (text items 2 thru -1 of theText) as text
set text item delimiters to ""
-- use grep and awk to pull out the titles from the rest of the text
set theTitles to paragraphs of (do shell script "echo " & quoted form of theGoodPart & " | grep '<title>' | awk -F '<title>' '{print $2}' | awk -F '</title>' '{print $1}'")
set theURL to "http://www.bungie.net/stats/halo3rss.ashx?g=AceHENDO13&md=3"
set theText to do shell script "curl " & quoted form of theURL without altering line endings
-- remove all of the text before the first <item> tag because you don't want titles from that section
set text item delimiters to "<item>"
set theGoodPart to (text items 2 thru -1 of theText) as text
set text item delimiters to ""
-- use grep and awk to pull out the titles from the rest of the text
set theTitles to paragraphs of (do shell script "echo " & quoted form of theGoodPart & " | grep '<title>' | awk -F '<title>' '{print $2}' | awk -F '</title>' '{print $1}'")
Ok I can’t seem to wrap my head around this table view thing…I’ve looked at lots of examples and just can’t figure it out…
I have a tableview with 5 columns. Right now I’m just trying to get one piece of data in the first row of the first column.
Thanks to regulus this script returns the exact string i want (I’m not sure if it’s going to have to be in list form before it’s put in the table view):
set theURL to "http://www.bungie.net/stats/halo3rss.ashx?g=AceHENDO13&md=3"
set theText to do shell script "curl " & quoted form of theURL without altering line endings
-- remove all of the text before the first <item> tag because you don't want titles from that section
set text item delimiters to "<item>"
set theGoodPart to (text items 2 thru -1 of theText) as text
set text item delimiters to ""
-- use grep and awk to pull out the titles from the rest of the text
set theTitles to paragraphs of (do shell script "echo " & quoted form of theGoodPart & " | grep '<title>' | awk -F '<title>' '{print $2}' | awk -F '</title>' '{print $1}'")
set gameInfo to item 1 of theTitles
set AppleScript's text item delimiters to {":"}
set gameTypeSource to text item 2 of gameInfo
set AppleScript's text item delimiters to {"on"}
set gameType to text item 1 of gameTypeSource
set AppleScript's text item delimiters to {""}
return gameType
Now I simply want to put the gameType variable in the first row of the first column in my table view and for the life of me i can’t get it to work
You need a list of lists… in the following form for your 5 column table {{1,2,3,4,5},{a,b,c,d,e}}. Each interior list is a row in your table. Each value of each interior list will be placed in the columns sequentially. Then you can show it in a table with the following…
set contents of table view “myTable” of window 1 to myList
That’s the simplest way. The most efficient way is to set up your list of lists as the data source of the table. You can also use a list of records if you prefer.
Ok, I need a little help parsing your place finish in each game. Heres the chunk of text that needs parsing
Now I have a gamertag variable (gt) set to AceHENDO13, but the problem is you’ll see next to my name there’s a colour in brackets, then my place finish. I was just going to use my gt variable as a text item delimeter but since the colour in brackets will be different in each entry that will not work. Is there any way to get my place finish (in this case 1st) isolated?
This works. The trick is to cut away all of the early text before your gamer name… then you can work on just what’s left… thus you can use “):” and “,” to pull out the info.
set theText to "Team game played at Sun, 25 Jan 2009 23:32:39 GMT<br/><br/>Playlist: Team Snipers<br/>Shotty Snipers on High Ground<br/><br/>Gamertag (Team): Standing, Score, Kills, Deaths, Assists<br/>Siberian Hottie (Red): 2nd, 44, 13, 8, 2<br/>bavneetbrar (Red): 2nd, 44, 6, 13, 5<br/>el Californio (Red): 2nd, 44, 13, 14, 8<br/>litteshooter (Red): 2nd, 44, 12, 15, 3<br/>AceHENDO13 (Blue): 1st, 50, 15, 12, 4<br/>xxAzurewrathxx (Blue): 1st, 50, 16, 10, 4<br/>j to the p 27 (Blue): 1st, 50, 12, 20, 5<br/>pwnzr117 (Blue): 1st, 50, 7, 3, 3<br/>"
set text item delimiters to "AceHENDO13"
set goodText to item 2 of (text items of theText)
set text item delimiters to "): "
set subGoodText to item 2 of (text items of goodText)
set text item delimiters to ","
set myPlace to first text item of subGoodText
set text item delimiters to ""
myPlace
I would guess that the date formatter is looking for something in date format, but your date is in string format. Or maybe it’s looking for a data in a specific string format but it can’t understand yours. In any case, since it’s in string format you can use text item delimiters to cut it up and show it any way you like. You should be able to use tids now since I showed you a few examples. If you still have trouble post what you tried and I’ll take a look.
I also now have the task of filling out more than one row and for loops are my nemesis (they just confuse me until my brain explodes)
My code to fill out one row looks like this:
on getRecentGames()
set theURL to "http://www.bungie.net/stats/halo3rss.ashx?g=" & gt & "&md=3"
set theText to do shell script "curl " & quoted form of theURL without altering line endings
-- remove all of the text before the first <item> tag because you don't want titles from that section
set text item delimiters to "<item>"
set theGoodPart to (text items 2 thru -1 of theText) as text
set text item delimiters to ""
-- use grep and awk to pull out the titles from the rest of the text
set theTitles to paragraphs of (do shell script "echo " & quoted form of theGoodPart & " | grep '<title>' | awk -F '<title>' '{print $2}' | awk -F '</title>' '{print $1}'")
set gameInfo to item 1 of theTitles
--return gameInfo
(* Get playlist *)
set AppleScript's text item delimiters to {""}
set playlistSource to (text items 1 thru -1) of gameInfo as string
set AppleScript's text item delimiters to {":"}
set thePlaylist to text item 1 of playlistSource
set AppleScript's text item delimiters to {""}
(* Get game type *)
set AppleScript's text item delimiters to {":"}
set gameTypeSource to text item 2 of gameInfo
set AppleScript's text item delimiters to {"on"}
set gameType to text item 1 of gameTypeSource
set gameType to (do shell script "echo " & quoted form of gameType & " | sed 's|^\\ *||'")
set AppleScript's text item delimiters to {""}
(* Get map *)
set AppleScript's text item delimiters to {"on"}
set mapSource to text items 2 thru -1 of gameInfo as string
set AppleScript's text item delimiters to {""}
set theMap to (do shell script "echo " & quoted form of mapSource & " | sed 's|^\\ *||'")
set AppleScript's text item delimiters to {""}
(* get all the other crap *)
set theDescrip to paragraphs of (do shell script "echo " & quoted form of theGoodPart & " | grep '<description>' | awk -F '<description>' '{print $2}' | awk -F '</description>' '{print $1}'")
set otherInfo to item 1 of theDescrip
--return otherInfo
(* Get place finish *)
set AppleScript's text item delimiters to {gt}
set placeSource to text item 2 of otherInfo
set AppleScript's text item delimiters to {","}
set thePlace to text item 1 of placeSource
set AppleScript's text item delimiters to {""}
set AppleScript's text item delimiters to {":"}
set thePlace to text item 2 of thePlace
set thePlace to (do shell script "echo " & quoted form of thePlace & " | sed 's|^\\ *||'")
set AppleScript's text item delimiters to {""}
(* Get date *)
set theDates to paragraphs of (do shell script "echo " & quoted form of theGoodPart & " | grep '<pubDate>' | awk -F '<pubDate>' '{print $2}' | awk -F '</pubDate>' '{print $1}'")
set theDate to item 1 of theDates
set theDate to (findAndReplace("GMT", "", theDate))
(* call placeData method *)
placeData()
end getRecentGames
on placeData()
(* set the data source *)
set dataSource to {""}
set rowData to {gameType, thePlace, theMap, thePlaylist, theDate}
set item 1 of dataSource to rowData
--set item 1 of dataSource to row1
tell window "recentGames"
set contents of table view "recentGamesView" of scroll view "scrollView" to dataSource
end tell
end placeData
Theres always going to be 10 entries so im assuming a repeat with i from 1 to 10 is necessary.
So im assuming this:
set gameInfo to item 1 of theTitles
will be changed to
repeat with i from 1 to 10
set gameInfo to item i of theTitles
--rest of code blah blah
end repeat
So atm my output looks like this:
But im not sure how to set up my rowData to handle more than one list, or how to put each row in a new list. gahhhhhh my head hurts
It seems like you’ve got lots of problems. The problems aren’t with applescript studio though, they are with applescript itself. My suggestion would be to take some time to learn applescript a little better. Building an application is a lot to tackle if you don’t understand the basics of applescript. This website has a great section of tutorials called Unscripted that can help. You can see it here: http://macscripter.net/viewforum.php?id=31
There is still something that is completely baffling my mind though.
To get all the stats in the list form to be ready for a table view, I did it in regular script editor first. I run it in script editor and it outputs everything exactly how it should like this
However, in my AS Studio app, I simply placed it in a method and called it on an on action() handler and it returns an error saying it can’t get text items 2 of
The term “text items” is used when you want to convert a string to a list using text item delimiters. You can get text item 2 from a string if the current text item delimiter is found in the string. If the text item delimiter is not found in the string then you will get back a list with only one item in it and thus you can’t get the second text item.
If you already have a list and you want to get the second item from the list then you don’t use “text item 2”. You just use “item 2”.