From 21fbc773f86cea169ada05339d7a01eab1e0f5e2 Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Tue, 16 Apr 2024 23:07:28 +0530 Subject: [PATCH] Use `json.dump()` instead of directly writing data --- main.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/main.py b/main.py index 24b002c..cb40d32 100644 --- a/main.py +++ b/main.py @@ -44,8 +44,12 @@ def initial_setup(): for f in databases: if not os.path.isfile(f"database/{f}.json"): logger.warn(f"[main/Setup] '{f}.json' was not found in database directory. Creating new database...", module="main/Setup", nolog=True) - if f == "currency": open(f"database/{f}.json", 'x', encoding="utf-8").write('{"treasury": 1000000, "wallet": {}, "bank": {}}') - else: open(f"database/{f}.json", 'x', encoding="utf-8").write("{}") + if f == "currency": + with open(f"database/{f}.json", 'x', encoding="utf-8") as f: + json.dump({"treasury": 1000000, "wallet": {}, "bank": {}}, f, encoding="utf-8") + else: + with open(f"database/{f}.json", 'x', encoding="utf-8") as f: + json.dump({}, f, encoding="utf-8") time.sleep(0.5) except IOError as e: logger.error(f"Failed to make database file: {e}", module="main/Setup")