-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.py
106 lines (83 loc) · 2.2 KB
/
main.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
import datetime
def addTodo(todo_item):
with open('todo.txt', 'a') as f:
f.write(todo_item)
f.write("\n")
def lsTodo():
todos = read_todos_from_db()
inx = len(todos)
content = []
for todo in reversed(todos):
cont = [("[{}] {}\n".format(inx, todo)), inx]
inx -= 1
content.append(cont)
return content
def completeTodo(no):
todos = read_todos_from_db()
no = int(no) - 1
f = open('done.txt', 'a')
st = 'x ' + str(datetime.datetime.today()).split()[0] + ' ' + todos[no]
f.write(st)
f.close()
with open("todo.txt", "r+") as f:
lines = f.readlines()
f.seek(0)
for i in lines:
if i != todos[no]:
f.write(i)
f.truncate()
def reportCompletedTodo():
completed = []
todos = read_todos_from_db()
don = {}
cont = ""
with open('done.txt', 'r') as nf:
c = 0
for line in nf:
c = c + 1
don.update({c: line})
cont += (
'{} Pending : {} Compleated : {}'
.format(str(datetime.datetime.today()).split()[0],
len(todos), len(don))
)
for value in don.values():
completed.append(value)
content = {
"cont": cont,
"completed": completed
}
return content
def updateTodo(no, new_item):
todos = read_todos_from_db()
no = int(no) - 1
with open("todo.txt", "r+") as f:
lines = f.readlines()
f.seek(0)
for i in lines:
if i != todos[no]:
f.write(i)
else:
f.write(new_item)
f.write("\n")
f.truncate()
def deleteTodo(no):
no = int(no) - 1
todos = read_todos_from_db()
with open("todo.txt", "r+") as f:
lines = f.readlines()
f.seek(0)
for i in lines:
if i != todos[no]:
f.write(i)
f.truncate()
def read_todos_from_db():
todos = []
try:
with open('todo.txt', 'r') as f:
for line in f:
line.strip('\n')
todos.append(line)
return todos
except Exception:
print("There are no pending todos!")