From e029ee7b7ec5370c91e63d3443ca810788c80555 Mon Sep 17 00:00:00 2001 From: Hykilpikonna Date: Sun, 22 Nov 2020 13:15:25 -0500 Subject: [PATCH] [+] Create toJson util method --- src/database.py | 3 ++- src/utils.py | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) create mode 100644 src/utils.py diff --git a/src/database.py b/src/database.py index 3b9de14..0f65e2a 100644 --- a/src/database.py +++ b/src/database.py @@ -1,6 +1,7 @@ import json from src.constants import dbPath +from src.utils import toJson class Database: @@ -10,5 +11,5 @@ class Database: def save(self): f = open(dbPath, 'w') - f.write(json.dumps(self)) + f.write(toJson(self)) f.close() diff --git a/src/utils.py b/src/utils.py new file mode 100644 index 0000000..d98f202 --- /dev/null +++ b/src/utils.py @@ -0,0 +1,5 @@ +import json + + +def toJson(obj): + return json.dumps(obj, default=lambda o: o.__dict__, sort_keys=True, indent=4)