SitePoint Sponsor |
|
User Tag List
Results 1 to 4 of 4
Thread: Reading an RSS 2 feed with Ruby
-
Jan 10, 2007, 02:21 #1
- Join Date
- Oct 2006
- Location
- San Francisco, CA
- Posts
- 38
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Reading an RSS 2 feed with Ruby
Hey there,
So I'm trying to use RSS:Parse to read in a RSS file from flickr
here's my current code. The problems is elements under item that are like "media:category"
how do I call these elements, and how do I get attributes of elements as well .
Here's my current code (not final, just trying to get it working before I prettify), which works if I take out the the item.media:category line
Code:unless photostream.tags.blank? and flickruser.nil? open(flickr_RSS_uri) do |http| response = http.read result = RSS::Parser.parse(response, false) result.items.each_with_index do |item, i| %> <%=item.link%> <%=item.title%> <%=item.media:category%> <% end end end
-
Jan 10, 2007, 10:58 #2
- Join Date
- Aug 2005
- Posts
- 986
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
media:category is not valid Ruby syntax. Could you give an example flickr RSS feed you're trying to read?
Is this a Rails template? You should put the rss reading code in your controller ;-).
-
Jan 10, 2007, 11:54 #3
- Join Date
- Oct 2006
- Location
- San Francisco, CA
- Posts
- 38
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Yes I am aware it is not valid ruby syntax, and yes it will go into the controller, this was just a mere convenience.
Here's an example of the RSS
http://api.flickr.com/services/feeds...format=rss_200
I've been playing with a different parse which is easier and doesn't have these problems, but still curious how to do it with RSS::PARSER
-
Jan 10, 2007, 13:13 #4
- Join Date
- Aug 2005
- Posts
- 986
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I think it isn't possible:
Code:irb(main):020:0> puts RSS::Parser.parse('http://api.flickr.com/services/feeds/ph otos_public.gne?id=40040707109@N01&format=rss_200', false).items.first <item> <title>light at the end</title> <link>http://www.flickr.com/photos/stuffandnonsense/350010253/</link> <description><p><a href="http://www.flickr.com/people/stuffandno nsense/">drain</a> posted a photo:</p> <p><a href="http://www.flickr.com/photos/stuffandnonsense/35001025 3/" title="light at the end"><img src="http://farm1.st atic.flickr.com/133/350010253_11c594ac01_m.jpg" width="180" heigh t="240" alt="light at the end" style="border: 1px solid #ddd;" /></a></p> </description> <category>tunnel baths sutro sfchronicle 96hours sfchronicle96hours</category> <author>nobody@flickr.com (drain)</author> <pubDate>Mon, 08 Jan 2007 05:47:28 +0100</pubDate> <guid isPermaLink="false">tag:flickr.com,2004:/photo/350010253</guid> </item> => nil
Bookmarks