From 04529cdd7697fac4af6001532f780aac60da49ed Mon Sep 17 00:00:00 2001 From: snipe <72265661+notsniped@users.noreply.github.com> Date: Wed, 1 May 2024 16:46:31 +0530 Subject: [PATCH] Improve code quality for database file checks --- main.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/main.py b/main.py index 190a6bd..6ce10dd 100644 --- a/main.py +++ b/main.py @@ -15,12 +15,11 @@ if not os.path.isdir("db"): print(f"[main/Startup] {colors.yellow}Database directory appears to be missing.{colors.end} Creating directory...") os.mkdir("db") -if not os.path.isfile("db/profiles.json"): - print(f"[main/Startup] {colors.yellow}\"profiles.json\" database appears to be missing.{colors.end} Creating database...") - with open("db/profiles.json", 'x', encoding="utf-8") as f: json.dump({}, f) -if not os.path.isfile("db/user_ratings.json"): - print(f"[main/Startup] {colors.yellow}\"user_ratings.json\" database appears to be missing.{colors.end} Creating database...") - with open("db/user_ratings.json", 'x', encoding="utf-8") as f: json.dump({}, f) +databases = ["profiles.json", "user_ratings.json"] +for database in databases: + if not os.path.isfile(f"db/{database}"): + print(f"[main/Startup] {colors.yellow}\"{database}\" database appears to be missing.{colors.end} Creating database...") + with open(f"db/{database}", 'x', encoding="utf-8") as f: json.dump({}, f) # Load Databases print("[main/Startup] Populating databases...")