diff --git a/py/api.py b/py/api.py index 646af55..b52870f 100644 --- a/py/api.py +++ b/py/api.py @@ -13,6 +13,7 @@ class API: self.ai_response = {} self.ai = AI() self.db = DB() + self.db.load_database() CORS(self.app) def run(self): diff --git a/py/db.py b/py/db.py index ef82111..76470c9 100644 --- a/py/db.py +++ b/py/db.py @@ -1,5 +1,5 @@ -import json import hashlib +import json class DB: @@ -26,6 +26,7 @@ class DB: return False self.database[username]['data'] = data + self.save_database() return True def update_password(self, data): @@ -36,6 +37,7 @@ class DB: hashed_new_password = self.hash_password(new_password) self.database[username].update({"hashed_password": hashed_new_password}) + self.save_database() return True def check_credentials(self, data): @@ -55,3 +57,14 @@ class DB: send_back = self.database[username].get['data'] return send_back + + def save_database(self): + with open("database.json", 'w') as file: + json.dump(self.database, file) + + def load_database(self): + try: + with open("database.json", 'r') as file: + self.database = json.load(file) + except FileNotFoundError: + pass