kastner / ruby-junk

my random ruby scripts

This URL has Read+Write access

ruby-junk / twitter-mentions.rb
ab9cb9af » Erik Kastner 2009-05-27 adding my rails template an... 1 require 'rubygems'
2 require 'open-uri'
3 require 'json'
4
5 base = "http://search.twitter.com/search.json?q=%s&rpp=100&page=%s"
6 mentions = Hash.new(0)
7
8 15.times do |page|
9 p = JSON.parse(open(base % ["etsy", page+1]).read)
10 p["results"].each do |tweet|
11 t = Time.parse(tweet["created_at"])
12 hours_ago = ((Time.now - t) / 60 / 60).to_i
13 mentions[hours_ago] += 1
14 end
15 end
16
17 results = mentions.sort.reverse
18 %x{open "http://chart.apis.google.com/chart?cht=lc&chs=300x125&chd=t:#{results.collect{|a| a[1]}.join(",")}"}