-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtasks.py
54 lines (42 loc) · 1.09 KB
/
tasks.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
44
45
46
47
48
49
50
51
52
53
import json
import os
from pathlib import Path
import secrets
path = os.path.join(Path(__file__).parent, "data") + "/"
file = path + 'tasks.json'
def startup():
if not os.path.exists(path):
os.mkdir(path)
if not os.path.exists(file):
with open(file, 'w') as f:
json.dump({}, f)
def readDb():
with open(file, 'r') as f:
return json.load(f)
def writeDb(data):
with open(file, 'w') as f:
json.dump(data, f, indent=True)
def addUser(username):
data = readDb()
data[username] = {
"default":[]
}
writeDb(data)
def addTask(username, project, title, description, deadline, tag):
data = readDb()
id = secrets.token_hex(16)
data[username][project].append({
'id': id,
'title': title,
'description': description,
'deadline': deadline,
'tag': tag
})
writeDb(data)
def removeTask(username, project, id):
data = readDb()
for i in data[username][project]:
if i['id'] == id:
del data[username][project][i]
writeDb(data)
addUser('snehashish2')