Skip to content

Instantly share code, notes, and snippets.

@smokeymonkey
Created June 18, 2014 06:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save smokeymonkey/327110c3fc1dc405e9da to your computer and use it in GitHub Desktop.
Save smokeymonkey/327110c3fc1dc405e9da to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
require 'rubygems'
require 'uri'
require 'net/http'
require 'json'
require 'date'
require 'twitter'
begin
CONSUMER_KEY = 'xxxxx'
CONSUMER_SECRET = 'xxxxx'
OAUTH_TOKEN = 'xxxxx'
OAUTH_TOKEN_SECRET = 'xxxxx'
twcli = Twitter::REST::Client.new do |config|
config.consumer_key = CONSUMER_KEY
config.consumer_secret = CONSUMER_SECRET
config.access_token = OAUTH_TOKEN
config.access_token_secret = OAUTH_TOKEN_SECRET
end
uri = URI.parse('http://worldcup.sfg.io/matches')
yday = Date.today - 1
res = Net::HTTP.start(uri.host, uri.port) {|http|
http.get(uri.request_uri)
}
json = JSON.parse(res.body)
json.each do |game|
if game['datetime'][0,10] == yday.to_s then
home_team = game['home_team']['country']
home_code = game['home_team']['code']
home_goal = game['home_team']['goals'].to_s
away_team = game['away_team']['country']
away_code = game['away_team']['code']
away_goal = game['away_team']['goals'].to_s
status = "[Yesterday's Decision] " \
+ home_team + ":" + home_goal + "-" + away_goal + ":" + away_team + " #" + home_code \
+ " #" + away_code + " #worldcup"
twcli.update(status)
sleep 5
end
end
rescue
print "RuntimeError: ", $!, "\n";
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment