Skip to content

Instantly share code, notes, and snippets.

@visnup
Forked from burnto/Show entries per day.rb
Created June 30, 2009 20:35
Show Gist options
  • Save visnup/138411 to your computer and use it in GitHub Desktop.
Save visnup/138411 to your computer and use it in GitHub Desktop.
huned's homework problem
# Detect rss feed, parse it, and report number of posts per date.
require 'rubygems'
require 'hpricot'
require 'open-uri'
# First find the rss
url = ARGV[0] || "http://twitter.com/burnto"
doc = Hpricot(open(url))
rss_url = doc.search("link[@type=\"application/rss+xml\"]").first.attributes["href"]
# Now open and parse the rss
doc = Hpricot(open(rss_url))
counts = Hash.new(0)
doc.search("item/pubdate").each{|d|
date = Date.parse(d.inner_html)
counts[date] += 1
}
# TODO - fold this into the above iteration, since that's in order anyway.
counts.keys.sort.each do |date|
puts "#{date} #{'=' * counts[date]}"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment