ジオタグ付きツイートの座標をRubyで見る簡単なプログラム

Twitter の HTTP GET で使える API を使って、キーワード検索したツイートのうちジオタグ付きのツイートの座標を表示するプログラムを Ruby で作成してみました。

the code

# geotweets.rb
%w{uri open-uri json}.map{|l|require l}
print "> "
while gets
  q = URI.escape($_.strip)
  JSON::parse(open("http://search.twitter.com/search.json?" + 
                   "q=#{q}&rpp=100&dummy=#{Time.now.to_i}").
              read)['results'].map{|r|
    g = r['geo']; p g if g} unless q.size == 0
  print "> "
end

examples

$ ruby geotweets.rb 
> java
{"coordinates"=>[-7.9963, 112.6474], "type"=>"Point"}
{"coordinates"=>[0.0, 0.0], "type"=>"Point"}
{"coordinates"=>[-7.9123, 112.6426], "type"=>"Point"}
{"coordinates"=>[-7.9123, 112.6426], "type"=>"Point"}
{"coordinates"=>[-7.9122, 112.6427], "type"=>"Point"}
{"coordinates"=>[-7.9122, 112.6427], "type"=>"Point"}
{"coordinates"=>[-7.9122, 112.6427], "type"=>"Point"}
{"coordinates"=>[-7.9123, 112.6425], "type"=>"Point"}
{"coordinates"=>[-7.9123, 112.6425], "type"=>"Point"}
{"coordinates"=>[-6.8838, 109.5648], "type"=>"Point"}
{"coordinates"=>[-6.8838, 109.5634], "type"=>"Point"}
{"coordinates"=>[-7.951, 112.6574], "type"=>"Point"}
{"coordinates"=>[-6.8853, 109.5573], "type"=>"Point"}
{"coordinates"=>[-35.8393, -71.6005], "type"=>"Point"}
{"coordinates"=>[-7.5377, 112.2499], "type"=>"Point"}
{"coordinates"=>[-6.8867, 109.5508], "type"=>"Point"}
{"coordinates"=>[-7.9617, 112.6504], "type"=>"Point"}
{"coordinates"=>[-6.889, 109.5448], "type"=>"Point"}
{"coordinates"=>[35.102, -77.031], "type"=>"Point"}
{"coordinates"=>[-6.8951, 109.5418], "type"=>"Point"}
{"coordinates"=>[-6.8982, 109.536], "type"=>"Point"}
> jakarta
{"coordinates"=>[-6.9382, 107.7392], "type"=>"Point"}
> tokyo
{"coordinates"=>[36.9641, 140.9026], "type"=>"Point"}
> hannover 
{"coordinates"=>[52.1259, 11.6707], "type"=>"Point"}
{"coordinates"=>[52.4189, 9.5967], "type"=>"Point"}
{"coordinates"=>[52.4189, 9.5967], "type"=>"Point"}
{"coordinates"=>[52.3771, 9.7415], "type"=>"Point"}
> hanover
{"coordinates"=>[33.8444, -117.9767], "type"=>"Point"}
> new york
{"coordinates"=>[40.7073, -74.0107], "type"=>"Point"}
> ^C
$