Thursday, 21 July 2011

Ruby and RSS

Started looking into access RSS from Ruby discovered it pretty much already built in as described in this article Consuming RSS Feeds with Ruby, full docs are available in the Ruby Standard Library.

Accessing an RSS Feed is as simple as the following code snippet.

require "rss"
rss_feed = "http://meekgonkey.blogspot.com/feeds/posts/default?alt=rss"
rss_content = ""
open(rss_feed) { |f|
rss_content = f.read
}
puts "Bytes read #{rss_content.length} from feed"
rss = RSS::Parser.parse(rss_content,false)
puts "Title: #{rss.channel.title}"
puts "RSS URL: #{rss.channel.link}"
puts "Total entries: #{rss.items.size}"
rss.items.each { |item|
puts item.title
puts item.link
puts item.date
puts "---"
}

Which when run produces something along the lines of;
Bytes read 115009 from feed
Title: Geek Monkey
RSS URL: http://meekgonkey.blogspot.com/
Total entries: 25
Twitter from Ruby
http://meekgonkey.blogspot.com/2011/07/twitter-from-ruby.html
Thu, 21 Jul 2011 13:20:00 +0100
---
Github
http://meekgonkey.blogspot.com/2011/07/github.html
Mon, 18 Jul 2011 13:59:00 +0100
---
Google Plus
http://meekgonkey.blogspot.com/2011/07/google-plus.html
Fri, 01 Jul 2011 10:50:00 +0100
---
WATIR makes a tester's life easier.
http://meekgonkey.blogspot.com/2011/06/watir-makes-testers-life-easier.html
Wed, 29 Jun 2011 14:36:00 +0100
---
Setting browser size and position with watir-webdriver
http://meekgonkey.blogspot.com/2011/06/setting-browser-size-and-position-with.html
Thu, 23 Jun 2011 09:22:00 +0100
---




Doodle's Geek Monkey by Alastair Montgomery

0 comments: