-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib_for_program.py
73 lines (57 loc) · 1.98 KB
/
lib_for_program.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import sys
import json
from tabulate import tabulate
def messages():
print(f"1. Add new task\n2. See tasks\n3. Delete task\n4. Reset tasks\n5. Edit task\n0. Exit ")
def choose(m):
if m == 1:
make_new_task()
elif m == 2:
read_new_tasks()
elif m == 3:
delete_new_tasks()
elif m == 4:
reset_tasks()
elif m == 5:
edit_task()
elif m == 0:
exit()
else:
print("Idk, pls repeate")
def make_new_task():
tasks_take = input("Enter your task: ")
description_take = input("Enter your description for task: ")
with open("tasks.json", mode="r", encoding="utf-8") as file:
data = json.load(file)
data[tasks_take] = description_take
with open("tasks.json", mode="w", encoding="utf-8") as file:
json.dump(data, file)
def read_new_tasks():
with open("tasks.json", mode="r", encoding="utf-8") as file:
data = json.load(file)
table_data = [(key, value) for key, value in data.items()]
print(tabulate(table_data, headers=["Tasks:", "Description"], tablefmt="fancy_grid"))
print(data)
def delete_new_tasks():
tasks_take_del = input("Enter your task for delete: ")
with open("tasks.json", mode="r", encoding="utf-8") as file:
data = json.load(file)
del data[tasks_take_del]
with open("tasks.json", mode="w", encoding="utf-8") as file:
json.dump(data, file)
def reset_tasks():
base = {}
with open("tasks.json", mode="w", encoding="utf-8") as file:
json.dump(base, file)
print("Cleared!")
def edit_task():
tasks_take_edit = input("Enter your task for edit: ")
description_take = input("Enter your description for task: ")
with open("tasks.json", mode="r", encoding="utf-8") as file:
data = json.load(file)
data[tasks_take_edit] = description_take
with open("tasks.json", mode="w", encoding="utf-8") as file:
json.dump(data, file)
def exit():
print("Goodbye!")
sys.exit()