Closed carlosvargas closed 8 years ago
i like this idea :+1:
First stab at it:
import json
def get_team_id(code):
"""Take in team ID, read JSON file to map ID to name"""
with open("teamcodes.json") as jfile:
data = json.load(jfile)
for key, value in data.iteritems():
if value == code:
print(key)
break
else:
click.secho("No team found for this code", fg="red", bold=True)
>>> get_team_id("LCFC")
Leicester City FC
>>> get_team_id("AFC")
Arsenal FC
>>> get_team_id("Watfordfc")
Watford FC
>>> get_team_id("EFFZEH")
1. FC Köln
>>> get_team_id("ASDASDASD")
No team found for this code
@carlosvargas That's something that we definitely should have! @thurask Can you send in a PR for that?
Sweet! Thanks @thurask.
@architv I still think we need the other option as well, since most of the time you know the name of your team and not the code.
$ soccer --team-lookup Arsenal
AFC
I think there'd be a lot of edge cases, though.
I mean, you'd have to know that Borussia Mönchengladbach is stored as "Bor. Mönchengladbach", since that's how it's labeled in the JSON file; you'd have to write the umlaut and abbreviation.
Perhaps instead of lookup, turn the JSON into a pretty-printed listing of team codes?
For example:
def list_team_codes():
"""List team names in alphabetical order of team ID."""
teamcodes = sorted(TEAM_NAMES.keys())
here = os.path.dirname(os.path.abspath(__file__))
with open(os.path.join(here, "teamcodes.json")) as jfile:
data = json.load(jfile)
for code in teamcodes:
for key, value in data.iteritems():
if value == code:
print(u"{0}: {1}".format(value, key))
break
$ soccer --list
ACM: AC Milan
AFC: Arsenal FC
AFCB: AFC Bournemouth
ATM: Club Atlético de Madrid
AVFC: Aston Villa FC
B04: Bayer Leverkusen
BIL: Athletic Club
BM: FC Bayern München
BMG: Bor. Mönchengladbach
BOR: FC Girondins de Bordeaux
BSC: Hertha BSC
BVB: Borussia Dortmund
CFC: Chelsea FC
CFC: Genoa CFC
CRY: Crystal Palace FC
...
@carlosvargas @thurask It should be possible to display the code corresponding for the closest match for a team name. I would give it a shot.
When trying to specify a specif team, the help flag just prints out a list of team code
however there's no way for the user to figure out what code belongs to what team.
Perhaps what we can do is add a command to be able to search or look at what each code represents.
or