Skip to content

Instantly share code, notes, and snippets.

@burnto
Created June 30, 2009 20:30
Show Gist options
  • Save burnto/138407 to your computer and use it in GitHub Desktop.
Save burnto/138407 to your computer and use it in GitHub Desktop.
# 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"]
doc = Hpricot(open(rss_url))
counts = {}
doc.search("item/pubdate").each{|d|
t = Time.parse(d.inner_html)
date = [t.year, t.month, t.day].join("/")
counts.has_key?(date) ? counts[date] += 1 : counts[date] = 1
}
# TODO - fold this into the above iteration, since that's in order anyway.
counts.keys.sort.each do |date|
print date
counts[date].times do print "=" end
print "\n"
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment