Skip to content

Instantly share code, notes, and snippets.

@niku niku/wcresult.rb forked from smokeymonkey/wcresult.rb
Last active Aug 29, 2015

Embed
What would you like to do?
#!/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
You can’t perform that action at this time.