architv/soccer-cli

EURO 2016 support

hotice opened this issue · 7 comments

Would it be possible to support EURO 2016, which is currently ongoing? It's supported by football-data.org: http://api.football-data.org/v1/soccerseasons/424

would be nice feature yep!

it is a good feature but its temporary because it happens once every 4 years...but based on the API, there is a key that maps to the Euros ("EC") and I am assuming they will have something for the World Cup and Copa America too. So if there is a way to integrate it such it we can use them in the future international tournaments then we should definitely have it 😄 👍

Hey Folks,
if you can't wait, here is a simple and dumb script that shows the current EURO 2016 results:

import json
import urllib2
from datetime import datetime
from dateutil import tz

req = urllib2.Request('http://api.football-data.org/v1/soccerseasons/424/fixtures')
req.add_header('X-Response-Control', 'minified')
response = urllib2.urlopen(req).read()
jsonData = json.loads(response)

from_zone = tz.tzutc()
to_zone = tz.tzlocal()

for fixture in jsonData['fixtures']:
    resultHome = fixture['result']['goalsHomeTeam']
    resultAway = fixture['result']['goalsAwayTeam']
    date = datetime.strptime(fixture['date'], '%Y-%m-%dT%H:%M:%SZ')
    date = date.replace(tzinfo=from_zone)
    date = date.astimezone(to_zone)

    if fixture['status'] == 'IN_PLAY':
        print('\n')

    print('{}  {}\t{}:{}  {} - {}'.format(
        date.strftime('%Y-%m-%d %H:%M'),
        fixture['status'] if not fixture['status'] == 'TIMED' else fixture['status'] + '\t',
        resultHome if not resultHome is None else '-',
        resultAway if not resultAway is None else '-',
        fixture['homeTeamName'],
        fixture['awayTeamName'],
    ))

    if fixture['status'] == 'IN_PLAY':
        print('\n')

Cheers

Nils

@DevNils on python 3.5.1 after i fixed imports gives me error :
TypeError: the JSON object must be str, not 'bytes

@jerkovicl Or just replace stdlib with requests:

import json
import requests
from datetime import datetime
from dateutil import tz

headers = {'X-Response-Control': 'minified'}
req = requests.get('http://api.football-data.org/v1/soccerseasons/424/fixtures', headers=headers)
jsonData = req.json()

etc...

Works here on 3.5.1:
europy

@thurask thx man, it works;)

@thurask thank you for this fix.