I am working on an advanced/tweaked version of the Iron Man Jarvis script and I need it too speak the top 3 stories from the RSS feed. Anyway how? Thanks.
Use
do shell script "curl " & theRSSfeed
to get the feed’s data and use AppleScript’s text item delimiters to chop off the tags and get the information you want.
What is the text item delimiter and how do you grab text from it? Sorry, I’m a semi noobie:(
Oh, and this is the feed in case you want it feed://www.nytimes.com/services/xml/rss/nyt/HomePage.xml
(edit: I now know what a text item delmiter is but your code won’t grab my feed
That is because you have the wrong url to the feed.
Try this.
curl http://feeds.nytimes.com/nyt/rss/HomePage
There are many posts on this forum on how to extract information from xml files.
My opinion is to use an xml library instead of text item delimiters. There is an osax
for xml and system events has some methods as well.
My personal preference is the Ruby gem Nokogiri.
I have compiled part of it but I get error message
Here is my code.
set P to paragraphs 3 thru 6 of (do shell script "curl " & "http://feeds.nytimes.com/nyt/rss/HomePage")
set tid to AppleScript's text item delimiters
set tData to {"http://feeds.nytimes.com/nyt/rss/HomePage"}
--> {"Audio", "Some Name Here", "Some Display Name Here", "http://somesite.com"}
repeat with oneP in P
set AppleScript's text item delimiters to ">"
set aPart to text item 2 of oneP
set AppleScript's text item delimiters to "<"
set end of tData to text item 1 of aPart
end repeat
set AppleScript's text item delimiters to tid
I am not having an issue getting the feed through curl. Maybe the site was down for maintenance for a short while.
Here is a Ruby example. It requires rubygems and nokogiri gem. Using a parsing library is much more accurate and succinct than text scraping.
The following script will speak: “Story {story number}: {Story title}” for each of the top three stories.