Skip to content

Instantly share code, notes, and snippets.

@mnlwldr
Created June 16, 2018 15:34
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mnlwldr/83373326174ce8dab25a333a9c36f0d3 to your computer and use it in GitHub Desktop.
Save mnlwldr/83373326174ce8dab25a333a9c36f0d3 to your computer and use it in GitHub Desktop.
Word Cup Today
#!/usr/bin/env python
import requests
from tabulate import tabulate
data = requests.get(url="http://worldcup.sfg.io/matches/today").json()
def status_color(status):
cstatus = {
'completed': '\033[92m',
'in progress': '\033[93m',
'future': '\033[94m'
}.get(status)
return cstatus + status + '\033[0m'
def get_team_info(team, game):
return {
"country": game[team]['country'],
"goals": game[team]['goals'],
"code": game[team]['code']
}
headers=['Status','Home','Score','Away', '#']
table = []
for game in data:
status = status_color(game['status'])
home = get_team_info("home_team", game)
away = get_team_info("away_team", game)
table.append([
status,
home['country'],
"{}:{}".format(home['goals'],away['goals']),
away['country'],
"#{}{}".format(home['code'],away['code'])
])
print(tabulate(table,headers=headers))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment