use configparser to load ini from current user home

This commit is contained in:
Robert Kaussow 2018-06-07 22:03:27 +02:00
parent f574d127db
commit 53ecae953c
3 changed files with 16 additions and 4 deletions

2
.gitignore vendored
View File

@ -94,3 +94,5 @@ ENV/
# Rope project settings
.ropeproject
.flake8
config.ini

View File

@ -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

4
example_config.ini Normal file
View File

@ -0,0 +1,4 @@
[API]
HOST = https://beta.api.core-networks.de/
USER = your.email@example.com
PASSWORD = secret