Skip to content

Instantly share code, notes, and snippets.

@thurask
Last active April 24, 2016 18:54
Show Gist options
  • Save thurask/0ece25eccaca963707a018413650e68b to your computer and use it in GitHub Desktop.
Save thurask/0ece25eccaca963707a018413650e68b to your computer and use it in GitHub Desktop.
soccer-cli db updater
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import requests
import json
def nuller(code):
return "null" if code is None else code
def stripper(leagueid, leaguename):
headers = {
'X-Auth-Token': '<API_KEY>'
}
req = requests.get("http://api.football-data.org/v1/soccerseasons/{0}/teams".format(leagueid), headers=headers)
data = req.json()["teams"]
dlist = [{"name": team["name"], "code": nuller(team["code"]), "id": team["_links"]["self"]["href"].split("/")[-1], "league": {"name": leaguename, "id": leagueid}} for team in data]
return dlist
LEAGUE_IDS = {
"BL": [394, "Bundesliga"],
"BL2": [395, "2. Bundesliga"],
"BL3": [403, "3. Liga"],
"FL": [396, "Ligue 1"],
"FL2": [397, "Ligue 2"],
"EPL": [398, "Premier League"],
"EL1": [425, "League One"],
"LLIGA": [399, "La Liga"],
"SD": [400, "Segunda Division"],
"SA": [401, "Serie A"],
"PPL": [402, "Primeira Liga"],
"DED": [404, "Eredivisie"],
"CL": [405, "Champions League"]
}
cleanlist = [stripper(val[0], val[1]) for val in LEAGUE_IDS.values()]
adict = {}
adict["teams"] = sum(cleanlist, [])
with open("teams.json", "w") as afile:
json.dump(adict, afile)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment