architv / soccer-cli

:soccer: Football scores for hackers. :computer: A command line interface for all the football scores.
MIT License
1.09k stars 220 forks source link

Look up a team code #69

Closed carlosvargas closed 8 years ago

carlosvargas commented 8 years ago

When trying to specify a specif team, the help flag just prints out a list of team code

--team [MCFC|BM|SWA|TSG|GUI|CRY|NAN|VFB|ACM|TOU|LOR|EIB|REN|EMP|Watfordfc|WBA|null|PAL|SEV|AFCB|ETI|JUVE|BMG|LFC|FCA|EFFZEH|SMC|GCF|SCB|WHU|FCB|M05|HSV|DAR|SUN|FCI|OSC|WOB|SGE|BOR|BSC|ATM|NUFC|VCF|ESP|CFC|THFC|FCG|S04|BIL|AFC|VIG|B04|H96|OLY|FCT|EFC|FIO|LCFC|ROM|MAR|SASS|SVW|Int|NIC|AVFC|PSG|LAC|NCFC|BVB|SFC|REI|MAD|MON|LAZ|MUFC|LUD|VALL|SCFC|VAL|MAL|SSC|RSS]

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.

$ soccer --team-lookup AFC
Arsenal

or

$ soccer --team-lookup Arsenal
AFC
ueg1990 commented 8 years ago

i like this idea :+1:

thurask commented 8 years ago

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
architv commented 8 years ago

@carlosvargas That's something that we definitely should have! @thurask Can you send in a PR for that?

carlosvargas commented 8 years ago

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
thurask commented 8 years ago

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?

thurask commented 8 years ago

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
...
architv commented 8 years ago

@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.