Permalink
Switch branches/tags
Nothing to show
Find file
Fetching contributors…
Cannot retrieve contributors at this time
40 lines (33 sloc) 943 Bytes
#!/usr/bin/env ruby
#
# geostats.rb -- eavesdrop on the twitter stream and count geotagged
# twoots
#
# Part of the twootr! "project", hosted on github:
# http://github.com/bleything/twootr
#
# Copyright (c) 2010, Ben Bleything
# Released under the MIT License
#
require 'uri'
require 'rubygems'
require 'yajl/http_stream'
REPORTING_THRESHOLD = 100
CREDENTIALS = YAML.load_file( 'credentials.yml' )[ 'twitter' ]
puts "Connecting to Twitter..."
auth_string = "#{CREDENTIALS['username']}:#{CREDENTIALS['password']}"
uri = URI.parse( "http://#{auth_string}@stream.twitter.com/1/statuses/sample.json" )
# counters
twoots = 0
tagged = 0
puts "*** Connecting..."
Yajl::HttpStream.get(uri, :symbolize_keys => true) do |hash|
twoots += 1
tagged += 1 if hash[:geo]
if twoots % REPORTING_THRESHOLD == 0
puts "- %d geotagged out of %d total, or %0.3f%%" % [
tagged, twoots,
tagged.to_f / twoots.to_f * 100.0
]
end
end