Skip to content

Instantly share code, notes, and snippets.

@metade
Created November 1, 2010 14:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save metade/658240 to your computer and use it in GitHub Desktop.
Save metade/658240 to your computer and use it in GitHub Desktop.
require 'rubygems'
require 'open-uri'
require 'json'
class SlotCars
attr_accessor :keywords
def self.start(keywords)
slotcars = SlotCars.new(keywords)
while(true)
p slotcars.speeds
sleep 30
end
end
def initialize(keywords)
@keywords = keywords
end
def speeds
now = Time.now
result = Hash.new(0)
keywords.each do |keyword|
url = "http://search.twitter.com/search.json?q=#{keyword}&rpp=100"
p url
data = JSON.parse(open(url).read)
data['results'].each do |tweet|
time = Time.parse(tweet['created_at'])
score = 1000 - (now - time)
next if (score < 0)
p [time, score]
result[keyword] += score
end
end
result
end
end
keywords = ARGV
SlotCars.start(keywords)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment