Skip to content

Instantly share code, notes, and snippets.

@niku
Forked from smokeymonkey/wcresult.rb
Last active August 29, 2015 14:02
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 niku/f33986ea4bc20ea7d200 to your computer and use it in GitHub Desktop.
Save niku/f33986ea4bc20ea7d200 to your computer and use it in GitHub Desktop.
#!/usr/bin/ruby
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.get(uri)
json = JSON.parse(res.body)
json.select { |game|
Date.parse(game['datetime']) == yday
}.map { |game|
home_team = game['home_team']['country']
home_code = game['home_team']['code']
home_goal = game['home_team']['goals']
away_team = game['away_team']['country']
away_code = game['away_team']['code']
away_goal = game['away_team']['goals']
"[Yesterday's Decision] #{home_team}:#{home_goal}-#{away_goal}:#{away_team} ##{home_code} ##{away_code} #worldcup"
}.each do |status|
twcli.update(status)
sleep 5
end
rescue
print "RuntimeError: ", $!, "\n";
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment