From 8a6b5981795fc65c994d8e42c78f23a6c8d10498 Mon Sep 17 00:00:00 2001 From: emkael Date: Thu, 5 Jan 2017 13:17:18 +0100 Subject: Refactoring - config loading helper --- ausbutler/config.py | 8 ++++++++ ausbutler/db.py | 10 +++------- butler.py | 8 ++------ 3 files changed, 13 insertions(+), 13 deletions(-) create mode 100644 ausbutler/config.py diff --git a/ausbutler/config.py b/ausbutler/config.py new file mode 100644 index 0000000..7a0f57d --- /dev/null +++ b/ausbutler/config.py @@ -0,0 +1,8 @@ +from os import path +import json +import __main__ + +def load_config(filename): + return json.load( + open(path.join(path.dirname(__main__.__file__), + 'config', filename + '.json'))) diff --git a/ausbutler/db.py b/ausbutler/db.py index 940c69d..e40fee5 100644 --- a/ausbutler/db.py +++ b/ausbutler/db.py @@ -1,15 +1,11 @@ -import json -from os import path - from sqlalchemy import create_engine from sqlalchemy.orm import sessionmaker -import __main__ +from .config import load_config def get_session(): session = sessionmaker(bind=create_engine( "mysql://{0[user]}:{0[pass]}@{0[host]}/{0[db]}".format( - json.load(open( - path.join(path.dirname(__main__.__file__), 'config', 'db.json') - ))))) + load_config('db') + ))) return session() diff --git a/butler.py b/butler.py index 655a11f..b73674c 100644 --- a/butler.py +++ b/butler.py @@ -1,10 +1,6 @@ -import json -from os import path - -import __main__ +from ausbutler.config import load_config from ausbutler.interface import Interface -i = Interface(json.load( - open(path.join(path.dirname(__main__.__file__), 'config', 'butler.json')))) +i = Interface(load_config('butler')) i.calculate_all() -- cgit v1.2.3