From bae4f0e42a5b0e1094ed9b109e127f9189d79558 Mon Sep 17 00:00:00 2001 From: Tristan Gosselin-Hane Date: Thu, 11 Oct 2018 23:30:27 -0400 Subject: [PATCH] Move configuration to seperate file --- config.py | 15 +++++++++++++++ webhook-bridge.py | 6 +++--- 2 files changed, 18 insertions(+), 3 deletions(-) create mode 100644 config.py diff --git a/config.py b/config.py new file mode 100644 index 0000000..2b18337 --- /dev/null +++ b/config.py @@ -0,0 +1,15 @@ +import json + +class Configuration(object): + def __init__(self, path): + try: + with open(path, 'r') as f: + self._config = json.load(f) + if self._config: + self.webhook_url = self._config["MAIN"]["WEBHOOK_URL"] + else: + print("error reading config") + exit(1) + except IOError: + print("error reading config") + exit(1) \ No newline at end of file diff --git a/webhook-bridge.py b/webhook-bridge.py index d8aeb1c..86ca762 100755 --- a/webhook-bridge.py +++ b/webhook-bridge.py @@ -8,6 +8,7 @@ import re import requests import json from optparse import OptionParser +from config import Configuration from minecraft import authentication from minecraft.exceptions import YggdrasilError @@ -67,10 +68,9 @@ def get_options(): def main(): options = get_options() - with open('config.json', 'r') as f: - _config = json.load(f) + config = Configuration("config.json") - WEBHOOK_URL = _config["MAIN"]["WEBHOOK_URL"] + WEBHOOK_URL = config.webhook_url if options.offline: print("Connecting in offline mode...")