[+] database: Create load()
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
import json
|
import json
|
||||||
|
import os
|
||||||
|
|
||||||
from src.constants import dbPath
|
from src.constants import dbPath
|
||||||
from src.utils import toJson
|
from src.utils import toJson
|
||||||
@@ -9,12 +10,21 @@ class Database:
|
|||||||
self.users = []
|
self.users = []
|
||||||
self.userRequests = {}
|
self.userRequests = {}
|
||||||
self.userStatus = {}
|
self.userStatus = {}
|
||||||
|
self.load()
|
||||||
|
|
||||||
def save(self):
|
def save(self):
|
||||||
f = open(dbPath, 'w')
|
f = open(dbPath, 'w')
|
||||||
f.write(toJson(self))
|
f.write(toJson(self))
|
||||||
f.close()
|
f.close()
|
||||||
|
|
||||||
|
def load(self):
|
||||||
|
if os.path.isfile(dbPath):
|
||||||
|
f = open(dbPath, 'r')
|
||||||
|
database = json.loads(f.read())
|
||||||
|
self.__dict__ = database
|
||||||
|
f.close()
|
||||||
|
print("Database loaded.")
|
||||||
|
|
||||||
def checkUser(self, user):
|
def checkUser(self, user):
|
||||||
if user not in self.users:
|
if user not in self.users:
|
||||||
self.users.append(user)
|
self.users.append(user)
|
||||||
|
|||||||
Reference in New Issue
Block a user