From 634ba02e76722e8c7f7b720779f48ac03e76f801 Mon Sep 17 00:00:00 2001 From: nico Date: Wed, 8 Apr 2020 13:27:52 +0200 Subject: [PATCH] config handeling * add proper configuration handeling to the metrics class --- ejabberdrpc.py | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/ejabberdrpc.py b/ejabberdrpc.py index 7de19e6..6a34cd0 100755 --- a/ejabberdrpc.py +++ b/ejabberdrpc.py @@ -355,19 +355,19 @@ class EjabberdMetrics: if __name__ == "__main__": - import os import json + from config import Config # load config - path = os.path.dirname(__file__) - with open("/".join([path, "config.json"]), "r", encoding="utf-8") as f: - config = json.load(f) + config = Config() - url = config['url'] if "url" in config else "http://[::1]:5280/api" - login = config['login'] if "login" in config else None - api = config['api'] if "api" in config else "rest" + # credentials and parameters + url = config.get('url', default='http://localhost:5280/api') + login = config.get('login', default=None) + api = config.get('api', default='rest') - metric = EjabberdMetrics(url, login=login, api=api) - - data = metric.get_all() + # init handler + metrics = EjabberdMetrics(url, login, api) + + data = metrics.get_all() print(json.dumps(data, indent=True))