Last active
March 5, 2018 00:00
-
-
Save khalido/7b2352cb4067bd077ad99064bbfc3507 to your computer and use it in GitHub Desktop.
[configparser] saving passwords etc in a ini file and pulling it into a script later. python code and sample config.ini file. See https://docs.python.org/3/library/configparser.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# see https://docs.python.org/3/library/configparser.html for deets | |
[twitter] | |
c_key = secret_secret_something | |
c_secret = secret_secret_something | |
a_token = secret_secret_something | |
a_secret = secret_secret_something | |
[AirVisual] | |
api_key = secret_secret_something |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# api keys are in config.ini to keep them out of github | |
import configparser | |
config = configparser.ConfigParser() | |
config.read('config.ini') | |
# print out the sections in the config file | |
print(f'The config file has the following sections: {config.sections()}') | |
try: | |
air_visual_api_key = config['AirVisual']["api_key"] | |
except KeyError: | |
print("Missing Key AirVisual in the config_air.ini file") | |
if air_visual_api_key is not None: | |
print("Successfully imported airvisual api key") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment