beauty overhaul of config.py

This commit is contained in:
b3yond 2018-11-06 16:23:47 +01:00
parent d964927a3f
commit bc7a4a72f8

View file

@ -1,6 +1,7 @@
import pytoml as toml
import os
def load_env():
"""
load environment variables from the environment. If empty, use default
@ -9,44 +10,44 @@ def load_env():
:return: config dictionary of dictionaries.
"""
with open('config.toml.example') as defaultconf:
config = toml.load(defaultconf)
configdict = toml.load(defaultconf)
try:
config['twitter']['consumer_key'] = os.environ['CONSUMER_KEY']
configdict['twitter']['consumer_key'] = os.environ['CONSUMER_KEY']
except KeyError:
pass
try:
config['twitter']['consumer_secret'] = os.environ['CONSUMER_SECRET']
configdict['twitter']['consumer_secret'] = os.environ['CONSUMER_SECRET']
except KeyError:
pass
try:
config['web']['host'] = os.environ['HOST']
configdict['web']['host'] = os.environ['HOST']
except KeyError:
pass
try:
config['web']['port'] = os.environ['PORT']
configdict['web']['port'] = os.environ['PORT']
except KeyError:
pass
try:
config['web']['contact'] = os.environ['CONTACT']
configdict['web']['contact'] = os.environ['CONTACT']
except KeyError:
pass
try:
config['mail']['mbox_user'] = os.environ['MBOX_USER']
configdict['mail']['mbox_user'] = os.environ['MBOX_USER']
except KeyError:
pass
try:
config['database']['db_path'] = os.environ['DB_PATH']
configdict['database']['db_path'] = os.environ['DB_PATH']
except KeyError:
pass
return config
return configdict
# read config in TOML format (https://github.com/toml-lang/toml#toml)