use configparser to load ini from current user home
This commit is contained in:
parent
f574d127db
commit
53ecae953c
2
.gitignore
vendored
2
.gitignore
vendored
@ -94,3 +94,5 @@ ENV/
|
||||
# Rope project settings
|
||||
.ropeproject
|
||||
|
||||
.flake8
|
||||
config.ini
|
||||
|
@ -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
4
example_config.ini
Normal file
@ -0,0 +1,4 @@
|
||||
[API]
|
||||
HOST = https://beta.api.core-networks.de/
|
||||
USER = your.email@example.com
|
||||
PASSWORD = secret
|
Reference in New Issue
Block a user