SitePoint Sponsor

User Tag List

Results 1 to 4 of 4

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Location
    San Francisco, CA
    Posts
    38
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow 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
    thanks

  2. #2
    SitePoint Guru
    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 ;-).

  3. #3
    SitePoint Enthusiast
    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

  4. #4
    SitePoint Guru
    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>&lt;p&gt;&lt;a href=&quot;http://www.flickr.com/people/stuffandno
    nsense/&quot;&gt;drain&lt;/a&gt; posted a photo:&lt;/p&gt;
    
    &lt;p&gt;&lt;a href=&quot;http://www.flickr.com/photos/stuffandnonsense/35001025
    3/&quot; title=&quot;light at the end&quot;&gt;&lt;img src=&quot;http://farm1.st
    atic.flickr.com/133/350010253_11c594ac01_m.jpg&quot; width=&quot;180&quot; heigh
    t=&quot;240&quot; alt=&quot;light at the end&quot; style=&quot;border: 1px solid
     #ddd;&quot; /&gt;&lt;/a&gt;&lt;/p&gt;
    
    </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
    The media:category has disappeared.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •