Skip to content

Instantly share code, notes, and snippets.

@robmiller
Created June 10, 2016 13:19
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 robmiller/3e5a27084f237b061a7d34281f3948e1 to your computer and use it in GitHub Desktop.
Save robmiller/3e5a27084f237b061a7d34281f3948e1 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require "json"
require "open-uri"
json = open("http://api.football-data.org/v1/soccerseasons/424/fixtures").read
fixtures = JSON.parse(json)
fixtures = fixtures["fixtures"]
finished_recently = fixtures.select do |f|
time_since_start = Time.now.utc - Time.parse(f["date"])
# if the game started 2h00m–2h59m ago (to allow for extra time or any
# other delays), then we're interested; this should mean only
# displaying games once when run hourly
within_two_hours = (7_200...10_800).cover?(time_since_start)
has_been_played = f["status"] != "TIMED"
within_two_hours && has_been_played
end
if finished_recently.empty?
puts "No fixtures finished recently"
exit 0
end
finished_recently.each do |f|
puts "%s %d - %d %s" % [f["homeTeamName"],
f["result"]["goalsHomeTeam"],
f["result"]["goalsAwayTeam"],
f["awayTeamName"]]
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment