-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson_manager.py
More file actions
31 lines (22 loc) · 936 Bytes
/
Copy pathjson_manager.py
File metadata and controls
31 lines (22 loc) · 936 Bytes
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
import json
from TaskClass import Task
from task_tracker import filename
def addfile():
tasks = {"tasks":[]}
with open(filename, 'w') as file:
json.dump(tasks, file, indent=4)
def load_to_json():
with open(filename, 'r') as file:
task_json = json.load(file)
task_json["tasks"] = Task.list_to_json()
with open(filename, 'w') as file:
json.dump(task_json, file, indent=4)
def load_from_json():
with open(filename, 'r') as file:
dict = json.load(file)
if not len(dict["tasks"]) == 0:
Task.id = dict["tasks"][-1]['id'] + 1
for task in dict["tasks"]:
task_object = Task(id=task["id"], title=task["description"],
status=task["status"], create_time=task["createdAt"], update_time=task["updatedA"])
Task.task_list.append(task_object)