use configparser to load ini from current user home
This commit is contained in:
parent
f574d127db
commit
53ecae953c
|
@ -94,3 +94,5 @@ ENV/
|
||||||
# Rope project settings
|
# Rope project settings
|
||||||
.ropeproject
|
.ropeproject
|
||||||
|
|
||||||
|
.flake8
|
||||||
|
config.ini
|
||||||
|
|
|
@ -7,6 +7,7 @@ import requests
|
||||||
import os
|
import os
|
||||||
import json
|
import json
|
||||||
import urlparse
|
import urlparse
|
||||||
|
import configparser
|
||||||
|
|
||||||
|
|
||||||
def api_auth(user, passwd, host):
|
def api_auth(user, passwd, host):
|
||||||
|
@ -22,11 +23,16 @@ def api_auth(user, passwd, host):
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
"""Main logic entrypoint"""
|
"""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
|
print auth_token
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,4 @@
|
||||||
|
[API]
|
||||||
|
HOST = https://beta.api.core-networks.de/
|
||||||
|
USER = your.email@example.com
|
||||||
|
PASSWORD = secret
|
Reference in New Issue