One of the commercial websites I implemented (www.bauhaus-bathrooms.co.uk) has a RSS feed for their news items. I have considered various alternatives for parsing the feed but nothing is more elegant and efficient than using Ruby. Here is an example snippet of it:


require 'rss/1.0'
require 'rss/2.0'
require 'open-uri'

source = "http://www.bauhaus-bathrooms.co.uk/news/rss.xml"
content=""

open(source) do |s|
  content = s.read
end

rss = RSS::Parser.parse(content,false)

puts "Root values"
print "RSS title: ", rss.channel.title, "\n"
print "RSS link: ", rss.channel.link, "\n"
print "RSS description: ", rss.channel.description, "\n"
print "RSS publication date: ", rss.channel.date, "\n"

puts "Item values"
print "number of items: ", rss.items.size, "\n"
print "title of first item: ", rss.items[0].title, "\n"
print "link of first item: ", rss.items[0].link, "\n"
print "description of first items: ", rss.items[0].description, "\n"
print "date of first items: ", rss.items[0].date, "\n"


Run the above on the command prompt and it should print out the requested properties of the feed.

It would be really good to be able to build a GUI interface using SHOES to display the feed contents. Might use that as a future project!

Leave a Reply

You must be logged in to post a comment.