architv / soccer-cli

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

Allow user to use either env variable or config file to load API token #40

Closed ueg1990 closed 8 years ago

ueg1990 commented 8 years ago

In this change, i have included both ways to loading an API token.

Here is how the config.py file is expected to look like:

footballdata = { "SOCCER_CLI_API_TOKEN" : "xxxxxxx" }

Saturn commented 8 years ago

This doesn't work for me. The exception never runs.

Also why is the config dict named footballdata?

Could we just do:

from config import config

# ...
api_token = config.get('SOCCER_CLI_API_TOKEN')

config.py

config = {
        "SOCCER_CLI_API_TOKEN": "38904ru093urw349rfphjwfiohewspf",
    }
ueg1990 commented 8 years ago

I can do that. You should remove ur comment as it has ur API key :P

So do you have an env variable? if not, then maybe make sure the key is correct or re-run the setup.py script. I do 'python setup.py develop'

Saturn commented 8 years ago

I do not have an env variable set but I have the key set in config.py.

I just made up that API_KEY :smile:

ueg1990 commented 8 years ago

hey, i think i found the reason why it didnt catch the exception...fixed it in latest commit

Saturn commented 8 years ago

Works for me now.

thurask commented 8 years ago

Maybe ConfigParser instead of a separate .py file?

Not sure if it's any better or worse.

architv commented 8 years ago

@ueg1990 Shouldn't there be an exception handler to import config.py. When a user installs the app for the forst time, it gives the error ImportError: No module named config. I'll add that in README anyway.

ueg1990 commented 8 years ago

Thats true. In the REAME.md, mention both options of env variable and defining a config file (the config file steps are similar to authtoken.py). You can show them an example of the config.py: config = { "SOCCER_CLI_API_TOKEN": "38904ru093urw349rfphjwfiohewspf", }