From 0bb014efec7585f72b7c9aeb8da271216f13aed9 Mon Sep 17 00:00:00 2001 From: Konrad Date: Fri, 27 Sep 2019 20:03:00 +0200 Subject: [PATCH] updated json object hook to convert string keys back to ints Signed-off-by: Konrad --- HSMensaW_botA.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/HSMensaW_botA.py b/HSMensaW_botA.py index 29dab4b..401339a 100644 --- a/HSMensaW_botA.py +++ b/HSMensaW_botA.py @@ -373,11 +373,16 @@ def get_now() -> str: return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S") -def as_enum(d): +def process_json(d: dict) -> Any: if "Language" in d: lang = d["Language"] return getattr(Language, lang) else: + if isinstance(d, dict): + try: + return {int(k): v for k, v in d.items()} + except ValueError: + return d return d @@ -393,7 +398,7 @@ translator = Translator() try: with open(config_filename, 'r') as config_file: - config = json.load(config_file, object_hook=as_enum) + config = json.load(config_file, object_hook=process_json) except FileNotFoundError as e: print('Error: config file "{}" not found: {}'.format(config_filename, e)) sys.exit(-1)