-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathJB_todo_list.py
127 lines (100 loc) · 3.35 KB
/
JB_todo_list.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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
from sqlalchemy import create_engine
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy import Column, Integer, String, Date
from sqlalchemy.orm import sessionmaker
from datetime import datetime, timedelta
Base = declarative_base()
engine = create_engine('sqlite:///todo.db?check_same_thread=False')
class Table(Base):
__tablename__ = 'task'
id = Column(Integer, primary_key=True)
task = Column(String, default='Nothing to do!')
deadline = Column(Date, default=datetime.today())
def __repr__(self):
return self.task
Base.metadata.create_all(engine)
Session = sessionmaker(bind=engine)
session = Session()
MENU = """1) Today's tasks
2) Week's tasks
3) All tasks
4) Missed tasks
5) Add task
6) Delete task
0) Exit"""
def main():
while True:
print(MENU)
choice = int(input())
print()
today = datetime.today()
if choice == 1:
print(f"Today {today.strftime('%d %b')}: ")
todays_list = session.query(Table).filter(Table.deadline == today.date()).order_by(Table.deadline).all()
rows = session.query(Table).order_by(Table.deadline).all()
if rows == []:
print("Nothing to do!")
else:
for i in todays_list:
print(i)
print()
elif choice == 2:
print("Week's tasks!")
for n in range(0,7):
weeks_tasks(n)
elif choice == 3:
rows = session.query(Table).order_by(Table.deadline).all()
if rows == []:
print("Nothing to do!")
else:
num = 1
for item in rows:
print(f"{num}. {item}. {item.deadline.strftime('%-d %b')}")
num+=1
print()
elif choice == 4:
missed_tasks()
elif choice == 5:
task = input("Enter task ")
deadline = datetime.strptime(input("Enter deadline"), '%Y-%m-%d')
new_row = Table(task=task, deadline=deadline)
session.add(new_row)
session.commit()
print("The task has been added!\n")
elif choice == 6:
delete_tasks()
elif choice == 0:
print("Bye!")
quit()
def weeks_tasks(n):
today = datetime.today() + timedelta(days=n)
print(f"{today.strftime('%A %d %b')}: ")
days_list = session.query(Table).filter(Table.deadline == today.date()).order_by(Table.deadline).all()
num = 1
if days_list == []:
print("Nothing to do!")
else:
for i in days_list:
print(f"{num}. {i}")
num+=1
print()
def missed_tasks():
today = datetime.today()
print("Missed tasks:")
days_list = session.query(Table).filter(Table.deadline < today.date()).order_by(Table.deadline).all()
num = 1
for i in days_list:
if days_list == []:
print("Nothing is missed!")
else:
print(f"{num}. {i} {i.deadline.strftime('%-d %b')}")
num+=1
print()
def delete_tasks():
task_to_delete = int(input("Choose the number of the task you want to delete:"))
days_list = session.query(Table).order_by(Table.deadline).all()
session.delete(days_list[task_to_delete-1])
session.commit()
print("The task has been deleted!")
if __name__ == "__main__":
main()