-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcompleted_tasks.py
More file actions
66 lines (52 loc) · 1.93 KB
/
completed_tasks.py
File metadata and controls
66 lines (52 loc) · 1.93 KB
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
from datetime import date
from main_functions import *
def complete_task():
if no_tasks(): return
system('clear')
print(complete_header)
list_valid_tasks()
complete_item = validate_task(complete_prompt, complete_header)
confirm_completion(complete_item)
def confirm_completion(task):
# task is a (name, index) tuple
confirm = confirmation(task[0])
system('clear')
if confirm == "y":
save_completed_task(to_do_list[task[1]])
del to_do_list[task[1]]
print("TASK MARKED AS COMLETE!\n".center(width))
else:
print("TASK COMPLETION ACTION CANCELLED\n".center(width))
def confirmation(task):
complete = input(f'\tAre you sure you want to mark "{task}" as complete? (y/n) ')
while complete != "y" and complete != "n":
print("\n\tPlease press 'y' for yes or 'n' for no.")
complete = input(f'\tAre you sure you want to mark "{task}" as complete? ')
return complete
def save_completed_task(task):
name = task['Task']
due_date = task['Due']
today = date.today()
completed_date = today.strftime('%m-%d-%Y')
completed_tasks.append({'Task':name, 'Due':due_date, 'Complete':completed_date})
def view_completed_tasks():
system('clear')
print("COMPLETED TASKS:\n".center(width))
if len(completed_tasks) == 0:
print(no_completed_tasks.center(width))
print('\n')
else:
sort_completed_list()
print_completed_list()
def sort_completed_list():
"""
Sorts the completed_task list in reverse chronological order
(most recently completed task is shown first)
"""
completed_tasks.sort(reverse=True, key = lambda x: datetime.datetime.strptime(x['Complete'], '%m-%d-%Y'))
def print_completed_list():
for item in completed_tasks:
task = item['Task']
completed_date = item['Complete']
print(f'{task:>30} –– Completed {completed_date:<30}'.center(width))
print('\n')