updated json object hook to convert string keys back to ints
Signed-off-by: Konrad <klux2@hs-mittweida.de>
This commit is contained in:
parent
4bf7266951
commit
0bb014efec
1 changed files with 7 additions and 2 deletions
|
@ -373,11 +373,16 @@ def get_now() -> str:
|
||||||
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
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:
|
if "Language" in d:
|
||||||
lang = d["Language"]
|
lang = d["Language"]
|
||||||
return getattr(Language, lang)
|
return getattr(Language, lang)
|
||||||
else:
|
else:
|
||||||
|
if isinstance(d, dict):
|
||||||
|
try:
|
||||||
|
return {int(k): v for k, v in d.items()}
|
||||||
|
except ValueError:
|
||||||
|
return d
|
||||||
return d
|
return d
|
||||||
|
|
||||||
|
|
||||||
|
@ -393,7 +398,7 @@ translator = Translator()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
with open(config_filename, 'r') as config_file:
|
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:
|
except FileNotFoundError as e:
|
||||||
print('Error: config file "{}" not found: {}'.format(config_filename, e))
|
print('Error: config file "{}" not found: {}'.format(config_filename, e))
|
||||||
sys.exit(-1)
|
sys.exit(-1)
|
||||||
|
|
Loading…
Reference in a new issue