-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdatabase.py
43 lines (37 loc) · 1.01 KB
/
database.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import os
import pickle
def read_database():
# check if the file exists
if os.path.exists("database.dat"):
# read file
print("loading database dont close!")
with open("database.dat", "rb") as file:
return pickle.load(file)
# if file does not exist return empty database
else:
return {
"users": {
"admin": {"username": "admin", "password": "admin1234", "role": "admin"}
},
"lists": [],
}
def write_database(database):
# write to file
print("saving database dont close!")
with open("database.dat", "wb") as file:
pickle.dump(database, file)
print("database saved!")
# database structure
# {
# "users": {
# "username": {"password": str, "role": str},
# },
# "lists": [
# {
# "owner": str,
# "access": [str],
# "title": str,
# "tasks": [{"task": str, "due": str, "completed": bool}],
# }
# ],
# }