Last active
August 29, 2015 14:02
-
-
Save DeMarko/3f6ca30095516f343f8d 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
#!/usr/bin/env ruby | |
require 'rubygems' | |
require 'open-uri' | |
require 'json' | |
worldcup_url = 'http://footballdb.herokuapp.com/api/v1/event/world.2014/round/' | |
round_token = 'today' | |
if ARGV.first | |
if ARGV.first.to_i > 20 | |
puts "Invalid argument: try round number (1-20) or no round number for today's matches" | |
exit | |
else | |
round_token = ARGV.first | |
end | |
end | |
url = URI.encode(worldcup_url + round_token) | |
round_data = JSON.parse(open(url).read) | |
puts "#{round_data["round"]["title"]} on #{round_data["round"]["start_at"]}"; | |
if (round_token == 'today') | |
puts "Today's games are:"; | |
end | |
round_data["games"].each { |game| | |
puts "\t#{game["team1_title"]} (#{game["team1_code"]}) #{game["score1"]}-#{game["score2"]} #{game["team2_title"]} (#{game["team2_code"]})"; | |
} | |
if (round_token == 'today') | |
puts "For live match info try this Google Search: https://www.google.com/search?q=world+cup" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment