forked from React-Group/interstellar_ai
It saves data now yay.
This commit is contained in:
parent
840654f9d1
commit
1d1705ebfa
2 changed files with 15 additions and 1 deletions
|
@ -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):
|
||||
|
|
15
py/db.py
15
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
|
||||
|
|
Loading…
Reference in a new issue