From 53ecae953c2c589e8d092b050850ee90c17eb44a Mon Sep 17 00:00:00 2001 From: Robert Kaussow Date: Thu, 7 Jun 2018 22:03:27 +0200 Subject: [PATCH] use configparser to load ini from current user home --- .gitignore | 2 ++ authenticator.py | 14 ++++++++++---- example_config.ini | 4 ++++ 3 files changed, 16 insertions(+), 4 deletions(-) create mode 100644 example_config.ini diff --git a/.gitignore b/.gitignore index 6a18ad4..66d6e2a 100644 --- a/.gitignore +++ b/.gitignore @@ -94,3 +94,5 @@ ENV/ # Rope project settings .ropeproject +.flake8 +config.ini diff --git a/authenticator.py b/authenticator.py index b5eee1a..802bba6 100644 --- a/authenticator.py +++ b/authenticator.py @@ -7,6 +7,7 @@ import requests import os import json import urlparse +import configparser def api_auth(user, passwd, host): @@ -22,11 +23,16 @@ def api_auth(user, passwd, host): def main(): """Main logic entrypoint""" - API_HOST = "https://beta.api.core-networks.de/" - API_USER = "your.email@example.com" - PASSWORD = "secret" - auth_token = r.json() + config_path = os.path.join(os.path.expanduser("~"), "config.ini") + config = configparser.ConfigParser() + config.read(config_path) + + API_HOST = config['API']['HOST'] + API_USER = config['API']['USER'] + PASSWORD = config['API']['PASSWORD'] + + auth_token = api_auth(API_USER, PASSWORD, API_HOST) print auth_token diff --git a/example_config.ini b/example_config.ini new file mode 100644 index 0000000..05e323b --- /dev/null +++ b/example_config.ini @@ -0,0 +1,4 @@ +[API] +HOST = https://beta.api.core-networks.de/ +USER = your.email@example.com +PASSWORD = secret