Skip to content

Instantly share code, notes, and snippets.

@makoto
Created December 13, 2009 23:20
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save makoto/255664 to your computer and use it in GitHub Desktop.
Save makoto/255664 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'tweetstream'
require 'pp'
require 'json'
a = {:name => 'Olly', :total => 0, :previous => 0, :speed => 0}
b = {:name => 'Joe', :total => 0, :previous => 0, :speed => 0}
start_time = Time.now.to_i
end_time = Time.now.to_i
TweetStream::Client.new(ENV['TW_USER'],ENV['TW_PASS']).track(a[:name], b[:name]) do |status|
current_time = Time.now.to_i
if current_time > start_time + 1
end_time = start_time
start_time = current_time
a[:speed] = a[:total] - a[:previous]
b[:speed] = b[:total] - b[:previous]
end_time = start_time
start_time = current_time
b[:previous] = b[:total]
a[:previous] = a[:total]
end
if (status[:text].match(/#{a[:name]}/i) || status[:text].match(/#{b[:name]}/i) ) && status[:text].match(/win/i)
a[:total] = a[:total] + 1 if status[:text].match(/#{a[:name]}/i)
b[:total] = b[:total] + 1 if status[:text].match(/#{b[:name]}/i)
a[:ratio] = a[:total].to_f / (a[:total] + b[:total]) * 100
b[:ratio] = b[:total].to_f / (a[:total] + b[:total]) * 100
result = JSON.generate([{:text => status[:text], :a => a, :b => b, :created_at => status[:created_at], :id => status[:id], :current_time => current_time }])
p result
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment