From c72351a22167f6232817d64c2c006d6b961841b8 Mon Sep 17 00:00:00 2001 From: starnakin Date: Sun, 4 Jun 2023 13:16:45 +0200 Subject: [PATCH] fix: create config file if doesn't exist --- config.py | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/config.py b/config.py index 4cdb664..99b6199 100644 --- a/config.py +++ b/config.py @@ -1,7 +1,22 @@ import json - -f = open('./config/config.json') - -data = json.load(f) + +try: + f = open('./config/config.json') + data = json.load(f) +except: + data = { + "database": { + "ip": "localhost", + "port": 3306, + "user": "user", + "password": "password" + } + } + + json_object = json.dumps(dictionary, indent=4) + + with open("config/config.json", "w") as outfile: + outfile.write(json_object) + database = data.get("database");