Skip to content

Instantly share code, notes, and snippets.

@dotob
Created June 12, 2012 10:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dotob/2916796 to your computer and use it in GitHub Desktop.
Save dotob/2916796 to your computer and use it in GitHub Desktop.
rss parsing with ruby and simplerss
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