-
-
Save fmasanori/1288160dad16cc473a53 to your computer and use it in GitHub Desktop.
import requests | |
jogos = requests.get('http://worldcup.sfg.io/matches').json() | |
for jogo in jogos: | |
if jogo['status'] in ('completed', 'in progress'): | |
print (jogo['home_team']['country'], jogo['home_team']['goals'], 'x', | |
jogo['away_team']['country'], jogo['away_team']['goals']) |
Here's my take on the world cup:
if worldcup:
pass
But nice code anyways. ;)
^ Lmao
World cup in six lines. Wait, six lines? Brazil confirmed!
@XenGi cool code
@dhagrow Marvin hitchhiker's guide to the galaxy "I was bored :/"
alunos do Python para zumbis na área akkakakaka.
from urllib import request
import json
resp = request.urlopen('http://worldcup.sfg.io/matches').read()
for jogo in json.loads(resp.decode('utf-8')):
if jogo['status'] == 'completed':
hora = jogo['datetime']
print (jogo['location'],(hora[0:10], hora[11:16]))
print ("Vencedor:", jogo['winner'])
print (jogo['home_team']['country'], jogo['home_team']['goals'], 'x', jogo['away_team']['country'], jogo['away_team']['goals'],"\n")
sair = str(input("Precione ENTER para sair"))
Awesome!
No meu Python so rodou assim (dei um espaço na terceira linha):
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':
print (jogo['home_team']['country'], jogo['home_team']['goals'], 'x', jogo['away_team']['country'], jogo['away_team']['goals'])
@ThaWeatherman
Always. If you post a "x lines" titled post, people will try to come up with a shorter version. Wait for the ruby samples to come :)
But let's all remember that in Python, readability is more important than concision. If you want to keep it small, readable and PEP8, you should not try to compress more than :
Note the 80 char limits. More lines, but way more readable.
You can always make any Python code fits on one line, either with exec() + and or ;. But what's the point ?
And with requests :
And even like that, it's rather add some lines to have decent variables names.
Otherwise, it's not Python code, anymore, it's perl.