Books I Like

Tuesday, October 13, 2009

Simple Feed Aggregator in Ruby

Ruby already has few RSS standard libraries (0.9, 1.0 , 2.0) in built, and it is good enough for simple purpose.

Today, I am trying to work on a simple feed aggregator, which could take multiple feed source url's and enlists the stories published there. I was tempted to use the standard library, however since it would not support the Atom standard, started looking for another library which supports both.

SimpleRSS lib by Lucas Carlson looks great.

So, here goes the code. You may extend it if you wish.


require 'simple-rss'
require 'open-uri'

class FeedAggregator
def initialize(urls)
@urls = urls
@feeds = []
read_feeds
end

def read_feeds
@urls.each { |url| @feeds.push(SimpleRSS.new(open(url).read)) }
end

def feed_source_counts
@feeds.each_with_index do |feed, index|
feed_source = "Feed Source [#{index}]: #{feed.channel.title}"
published_articles = "Published Articles: #{feed.items.size}"
puts feed_source + ', ' + published_articles
end
end

def list_articles(id)
puts "-----Feed Source [#{id}] : #{@feeds[id].channel.title}-----"
@feeds[id].items.each { |item| puts ' ' + item.title }
end

def list_all_articles
@feeds.each_with_index { |f, i| list_articles(i) }
end
end

MyFeedAggregator = FeedAggregator.new(ARGV)
MyFeedAggregator.feed_source_counts
puts "------------ Feed Details ------------------"
MyFeedAggregator.list_all_articles



Here is the test run :


C:\Ruby\bin\ruby.exe -e STDOUT.sync=true;STDERR.sync=true;load($0=ARGV.shift) C:/Users/anshu/RubymineProjects/TestRubyProjectTwo/test_two.rb http://rubyforge.org/export/rss_sfnewreleases.php http://www.dzone.com/links/feed/frontpage/rss.xml
Feed Source [0]: RubyForge New Releases, Published Articles: 10
Feed Source [1]: dzone.com: latest front page, Published Articles: 25
------------ Feed Details ------------------
-----Feed Source [0] : RubyForge New Releases-----
Dr Nic's Utilities
WysMacs Trainable Text and Code Editor
Loofah
autotest-fsevent
state_pattern
codeforpeople
Seattle.rb Projects
rjack
snk's open source
Spidr
-----Feed Source [1] : dzone.com: latest front page-----
Non-Technical Factors that Lead to Poor Architectures
My Tools of the Trade รข€“ 2009
Week Calendar using Jquery
Oracle Taunts IBM with $10M Challenge
Rant about developers or how I stopped worrying and love the simplicity
ScalaTest 1.0 Release "A Path Forward" to Scala
Resolving a Relative URL to a Full URL in ASP.NET
JxBrowser 2.0 Early Access Program
PrimeFaces UI 0.9.3 Released
Mozilla Join Microsoft in Slamming Google Chrome Frame
TDD is not test-first. TDD is specify-first and test-last.
Five super-secret features in Windows 7
Git# Offers Git Access for .NET and Mono Projects
Getting Started with Scrum
Apparent risk and actual risk
8 Hand Drawn Icon Sets For Bloggers
Optimize your Mac experience with the LaunchBar multitasker
18 Really Beautiful and Creative Web Designs
Google Released Page Speed for Firefox
Objective-C's niche: why it survives in a world of alternatives
Mobile Ajax Push for iPhone with JSF and PrimeFaces
Book Review - Spring in Practice
Tips for Designing an Awesome Coming Soon Page
Abstracting away Dependencies for Simpler code
MacRuby 0.5 Pulls the Plug on YARV

Process finished with exit code 0

5 comments:

karim said...

Very thoughtfull post on Personal Development . It should be very much helpfull.

Thanks,
Karim - Positive thinking

Anonymous said...

[u][b]Xrumer[/b][/u]

[b]Xrumer SEO Professionals

As Xrumer experts, we from been using [url=http://www.xrumer-seo.com]Xrumer[/url] for the benefit of a long leisure conditions and grasp how to harness the massive power of Xrumer and adapt it into a Bills machine.

We also purvey the cheapest prices on the market. Many competitors will order 2x or even 3x and a a pile of the opportunity 5x what we debt you. But we feel in providing enormous accommodation at a debilitated affordable rate. The large direct attention to of purchasing Xrumer blasts is because it is a cheaper surrogate to buying Xrumer. So we train to support that thought in recollection and yield you with the cheapest rate possible.

Not solitary do we cause the unexcelled prices but our turnaround heyday payment your Xrumer posting is wonderful fast. We will take your posting done in the forefront you certain it.

We also outfit you with a full log of well-heeled posts on manifold forums. So that you can get the idea over the extent of yourself the power of Xrumer and how we have harnessed it to help your site.[/b]


[b]Search Engine Optimization

Using Xrumer you can trust to apprehend thousands upon thousands of backlinks for your site. Many of the forums that your Location you intent be posted on bear great PageRank. Having your join on these sites can deep down help build up some cover rank back links and uncommonly boost your Alexa Rating and Google PageRank rating owing to the roof.

This is making your site more and more popular. And with this increase in regard as familiarly as PageRank you can envisage to see your milieu absolutely rank expensive in those Search Motor Results.
Above

The amount of traffic that can be obtained before harnessing the power of Xrumer is enormous. You are publishing your site to tens of thousands of forums. With our higher packages you may equivalent be publishing your locale to HUNDREDS of THOUSANDS of forums. Create 1 brief on a all the rage forum drive by enter 1000 or so views, with signify 100 of those people visiting your site. Modern create tens of thousands of posts on celebrated forums all getting 1000 views each. Your shipping will associate sometimes non-standard due to the roof.

These are all targeted visitors that are interested or curious in the matter of your site. Imagine how divers sales or leads you can succeed in with this great loads of targeted visitors. You are in fact stumbling upon a goldmine friendly to be picked and profited from.

Retain, Shipping is Money.
[/b]

BECOME ENTHUSIASTIC ABOUT YOUR CHEAPLY DEFAME TODAY:


http://www.xrumer-seo.com

Anonymous said...

Make a trip Our Muffled Prices at www.Pharmashack.com, The Amazing [b][url=http://www.pharmashack.com]Online Fairly [/url][/b] To [url=http://www.pharmashack.com]Buy Viagra[/url] Online ! You Can also Details to Unresponsive Deals When You [url=http://www.pharmashack.com/en/item/cialis.html]Buy Cialis[/url] and When You You [url=http://www.pharmashack.com/en/item/levitra.html]Buy Levitra[/url] Online. We Also Be subjected to a Foremost Generic [url=http://www.pharmashack.com/en/item/phentermine.html]Phentermine[/url] As a wane to Your Aliment ! We Vend Pinpoint honour [url=http://www.pharmashack.com/en/item/viagra.html]Viagra[/url] and Also [url=http://www.pharmashack.com/en/item/generic_viagra.html]Generic Viagra[/url] !

Anonymous said...

Predilection casinos? into this latest [url=http://www.realcazinoz.com]casino[/url] commander and advance up online casino games like slots, blackjack, roulette, baccarat and more at www.realcazinoz.com .
you can also spirited our untrained [url=http://freecasinogames2010.webs.com]casino[/url] par‘nesis at http://freecasinogames2010.webs.com and overwhelmed by law exacting currency !
another glint [url=http://www.ttittancasino.com]casino spiele[/url] develop is www.ttittancasino.com , in gain german gamblers, eradicate upon via unrestrained online casino bonus.

Anonymous said...

buy bactrim online buy bactrim f buy bactrim es online without prescription buy bactrim without prescription buy bactrim without a prescription overnight buy bactrim
[url=http://bactrim.eventbrite.com/]buy bactrim without prescription [/url]
buy bactrim without prescription
buy glucophage glucophage and pcos glucophage during pregnancy when to take glucophage doses glucophage assisted hip growth glucophage weight loss when to take glucophage
[url=http://takeglucophage.eventbrite.com/]what is glucophage [/url]
glucophage weight loss
proscar hair loss flomax plus proscar psa proscar flomax proscar for hair loss proscar news prostititis proscar proscar and flomax taken together
[url=http://proscar.eventbrite.com/]libido proscar [/url]
proscar side effects
canada in levitra free levitra trial temporary impotence genuine levitra no prescription impotence solution levitra attorneys impotence information
[url=http://virb.com/yalevi]libidus [/url]
male impotency
zithromax antibiotic zithromax package insert zithromax pharmacy generic zithromax azithromycin 500mg prescription zithromax zithromax urinary tract infection zithromax 500
[url=http://virb.com/bono]zithromax cost [/url]
generic zithromax online
-------------------------------------------------------------------
[url=http://fotak.ru/stats.php?r=anshu-manymoods.blogspot.com]my blog[/url]
blog my

Get at Amazon