Created
June 16, 2018 15:34
-
-
Save mnlwldr/83373326174ce8dab25a333a9c36f0d3 to your computer and use it in GitHub Desktop.
Word Cup Today
This file contains hidden or 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 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