Created
November 1, 2010 14:23
-
-
Save metade/658240 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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