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

Add API key writer #73

Closed thurask closed 8 years ago

thurask commented 8 years ago

In the event of no API key environment variable/config.py, notify user that there's no API key. Once user gets an API key, record it and save it to config.py file in site-packages.

[py2] C:\Users\thurask\git\soccer-cli>soccer
No API key found!
Please visit http://api.football-data.org/alpha/ and get an API token.
Please enter API key: <api_key>
Config file written! Please restart Soccer CLI.

[py2] C:\Users\thurask\git\soccer-cli>soccer --league EPL --standings
POS     CLUB                              PLAYED        GOAL DIFF     POINTS
1       Leicester City FC                 32            24            69
...
Saturn commented 8 years ago

I think the api key should be written to a user accessible folder. ie their home folder. Maybe AppData/ on Windows for example.

This avoids the issue of not having permissions. Is it a bad practice to write to the packages folders anyway?

And that is only if the user needs any hand holding at all. I think it is cleaner just to use environment variables. For example I could just add a single line to my .zshrc and be done with it.

Does anyone know how other python packages might handle this?

thurask commented 8 years ago

@Saturn

One could make ~/soccer-cli.ini (/home/user/soccer-cli.ini or C:\Users\user\soccer-cli.ini) a plain text file with just the key, instead of using a config.py.

Or, bust out ConfigParser, but I see no reason why.