Created
June 12, 2012 10:32
-
-
Save dotob/2916796 to your computer and use it in GitHub Desktop.
rss parsing with ruby and simplerss
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'simple-rss' | |
require 'open-uri' | |
class RssReader | |
def parseFeed (url, length) | |
feed_url = url | |
result = SimpleRSS.parse open(feed_url) | |
output = "<html><meta charset=\"utf-8\"><body>"; | |
output += "<h1>#{result.channel.title}</h1><br />" | |
result.items.each_with_index do |item, i| | |
if ++i < length | |
output += "<h2><a href=\"#{item.link}\">#{item.title}</a></h2>" | |
output += "<h3>#{item.author}</h3>" | |
output += "<p>#{item.summary}</p>" | |
output += "<br />" | |
output += "<br />" | |
end | |
end | |
output += "</body></html>" | |
return output | |
end | |
end | |
rr = RssReader.new | |
len = if ARGV.length == 3 then ARGV[2] else 10 end | |
html = rr.parseFeed(ARGV[0], len.to_i) | |
aFile = File.new(ARGV[1], "w") | |
aFile.write(html) | |
aFile.close |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment