-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathadd_functions.py
More file actions
60 lines (47 loc) · 1.38 KB
/
add_functions.py
File metadata and controls
60 lines (47 loc) · 1.38 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
import datetime
from os import system
from file_functions import *
# set width of console
width = 65
def add_task():
system('clear')
print("ADD A TASK\n".center(width))
name = get_task_name("New task name (enter -1 to cancel): ")
if name != "-1":
insert_new_task(name)
else:
system('clear')
print("CREATE TASK CANCELLED\n".center(width))
def insert_new_task(name):
due_date = get_due_date("Due date (MM-DD-YYYY): ")
message = get_message(due_date)
to_do_list.append({'Task':name, 'Due':due_date, 'Msg':message})
system('clear')
print("TASK ADDED!\n".center(width))
def get_task_name(prompt):
name = input(prompt)
while not valid_name(name.capitalize()) or name == "":
if name == "":
print("\nName cannot be blank")
else:
print("\nTask name already exists.")
name = input(prompt)
return name.capitalize()
def valid_name(new_name):
for task in to_do_list:
name = task['Task']
if new_name == name:
return False
return True
def get_due_date(prompt):
date = input(prompt)
while not valid_date(date):
print("\nInvalid format.")
date = input(prompt)
return date
def valid_date(date):
try:
datetime.datetime.strptime(date, "%m-%d-%Y")
return True
except ValueError:
return False