architv / soccer-cli

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

Convert team database to JSON #83

Closed thurask closed 8 years ago

thurask commented 8 years ago

Replaces teamnames.py and teamcodes.json with teams.json.

Inside teams.json is a list of entries like so:

...
    {  
      "id":"110",
      "league":{  
        "id":401,
        "name":"Serie A"
      },
      "code":"LAZ",
      "name":"SS Lazio"
    },
    {  
      "id":"103",
      "league":{  
        "id":401,
        "name":"Serie A"
      },
      "code":"null",
      "name":"Bologna FC"
    },
    {  
      "id":"108",
      "league":{  
        "id":401,
        "name":"Serie A"
      },
      "code":"INT",
      "name":"FC Internazionale Milano"
    },
    {  
      "id":"102",
      "league":{  
        "id":401,
        "name":"Serie A"
      },
      "code":"null",
      "name":"Atalanta BC"
    },
...

Rewrites main.py to accomodate JSON changes. Adds team_names() function to replicate functionality of former TEAM_NAMES global, at least for now.

New JSON is both much larger than old database, and human-readable, explaining the size increase. Many more team codes added, some changed ("Int" -> "INT", "Watfordfc" -> "WAT", "EFFZEH" -> "FCK" notably) without affecting functionality.

As a result of new JSON, team code listing is now able to be grouped by league: soccercolorsort

It is also colorized, as well as the team code lookup.

Lastly, add missing help text to --apikey argument.

carlosvargas commented 8 years ago

Good idea. One comment though:

There's a couple of teamnames().get, which will cause the json file to be read every single time. We can probably memoize that function since that data won't change between calls.

carlosvargas commented 8 years ago

Now that I think about it, is there a reason why we can't just put the teams into a dictionary instead of a json file? It would save us the trouble of having to read the file and parse it ourselves.

thurask commented 8 years ago

Okay, the app loads teams.json once now.

As for using a dict, I prefer using JSON/some other actual DB system for something as big as this team list.

Saturn commented 8 years ago

Did you use a script to build the new JSON? Was there a lot of manual work involved in its creation?

thurask commented 8 years ago

Mostly script. A little manual cleanup at the end (manually removed duplicates that were in the Champions League, changed some team codes).

https://gist.github.com/thurask/0ece25eccaca963707a018413650e68b