changed json format to exclude redundant information
Signed-off-by: Konrad <klux2@hs-mittweida.de>
This commit is contained in:
parent
9e0622e985
commit
2fd4dab43f
1 changed files with 8 additions and 12 deletions
|
@ -63,7 +63,7 @@ botID = -1
|
|||
class EnumEncode(json.JSONEncoder):
|
||||
def default(self, obj):
|
||||
if type(obj) is Language:
|
||||
return {"Language": str(obj.name)}
|
||||
return str(obj.name)
|
||||
return json.JSONEncoder.default(self, obj)
|
||||
|
||||
|
||||
|
@ -367,15 +367,11 @@ def get_now() -> str:
|
|||
return datetime.datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
|
||||
|
||||
def process_json(d: dict) -> Any:
|
||||
if "Language" in d:
|
||||
lang = d["Language"]
|
||||
return getattr(Language, lang)
|
||||
else:
|
||||
def process_json(d):
|
||||
if isinstance(d, dict):
|
||||
try:
|
||||
return {int(k): v for k, v in d.items()}
|
||||
except ValueError:
|
||||
return {int(k): getattr(Language, v) for k, v in d.items()}
|
||||
except (ValueError, TypeError):
|
||||
return d
|
||||
return d
|
||||
|
||||
|
|
Loading…
Reference in a new issue