-
-
Save rogerallen/33c7562ecf2d16ce2277 to your computer and use it in GitHub Desktop.
readable world cup output
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
> ./wc.py | |
BRAZIL 3 x 1 croatia | |
MEXICO 1 x 0 cameroon | |
spain 1 x 5 NETHERLANDS | |
CHILE 3 x 1 australia | |
COLOMBIA 3 x 0 greece | |
IVORY COAST 2 x 1 japan | |
uruguay 1 x 3 COSTA RICA | |
england 1 x 2 ITALY | |
SWITZERLAND 2 x 1 ecuador | |
FRANCE 3 x 0 honduras | |
ARGENTINA 2 x 1 bosnia and herzegovina | |
iran 0 x 0 NIGERIA | |
GERMANY 4 x 0 portugal | |
ghana 1 x 2 USA | |
BELGIUM 2 x 1 algeria | |
russia 1 x 1 KOREA REPUBLIC | |
brazil 0 x 0 MEXICO | |
cameroon 0 x 4 CROATIA | |
spain 0 x 2 CHILE | |
australia 2 x 3 NETHERLANDS | |
COLOMBIA 2 x 1 ivory coast | |
japan 0 x 0 GREECE in progress | |
URUGUAY 2 x 1 england |
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 python3 | |
import urllib.request | |
import json | |
resp = urllib.request.urlopen('http://worldcup.sfg.io/matches').read() | |
for jogo in json.loads(resp.decode('utf-8')): | |
if jogo['status'] == 'completed' or jogo['status'] == 'in progress': | |
status = jogo['status'] | |
if status == 'completed': | |
status = "" | |
if jogo['home_team']['goals'] > jogo['away_team']['goals']: | |
print("%24s %d x %d %-24s %s"%(jogo['home_team']['country'].upper(), jogo['home_team']['goals'], jogo['away_team']['goals'], jogo['away_team']['country'].lower(), status)) | |
else: | |
print("%24s %d x %d %-24s %s"%(jogo['home_team']['country'].lower(), jogo['home_team']['goals'], jogo['away_team']['goals'], jogo['away_team']['country'].upper(), status)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment