-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtodolist.py
More file actions
111 lines (86 loc) · 3.76 KB
/
todolist.py
File metadata and controls
111 lines (86 loc) · 3.76 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
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
import sqlite3
connection = sqlite3.connect(""ActivityDataBase.db")
cursor = connection.cursor()
try:
cursor.execute("""CREATE TABLE listTable(
level TEXT,
time TEXT,
desc TEXT
);""") # time activity is the KEY file
print("New table has been created!")
except:
print("Existing table found!")
def show_act(choice):
if choice is "Y" or choice is "y":
cursor.execute("SELECT * FROM listTable WHERE level = \"HIGH\"")
for index, row in enumerate(cursor.fetchall(), start = 1):
print("{}. Type: {}\tTime: {}\n Description:\n {}\n".format(index, row[0], row[1], row[2]))
cursor.execute("SELECT * FROM listTable WHERE level = \"MEDIUM\"")
for index, row in enumerate(cursor.fetchall(), start = 1):
print("{}. Type: {}\tTime: {}\n Description:\n {}\n".format(index, row[0], row[1], row[2]))
cursor.execute("SELECT * FROM listTable WHERE level = \"LOW\"")
for index, row in enumerate(cursor.fetchall(), start = 1):
print("{}. Type: {}\tTime: {}\n Description:\n {}\n".format(index, row[0], row[1], row[2]))
else:
cursor.execute("SELECT * FROM listTable")
for index, row in enumerate(cursor.fetchall(), start = 1):
print("{}. Type: {}\tTime: {}\n Description:\n {}\n".format(index, row[0], row[1], row[2]))
def add_act(act_type, act_time, act_des):
cursor.execute("INSERT INTO listTable VALUES(?, ?, ?)", (act_type, act_time, act_des))
print("New Activity Has been Added!")
connection.commit()
def del_act(time):
cursor.execute("DELETE FROM listTable WHERE time = \"{}\"".format(time))
print("Activity has been deleted!")
connection.commit()
def print_blanks():
for a in range(20):
print("\n")
def set_time_input():
while True: # loop until return
times = input("set time between 00:00 to 24:00: ")
try: # if user input wrong format!
time = times.split(":")
if int(time[0]) <= 24 and int(time[0]) >= 0 and int(time[1]) <= 60 and int(time[1]) >= 0:
if int(time[0]) >= 24 and int(time[1]) > 0: #time cannot more than 24:00
print("time is not correct!\n")
continue
else:
return times #here is the function returns string
else:
print("You enter the wrong time!\n")
except:
print("wrong input format! must be [hh:mm]") # if anything happens, it forces user to re-input
return set_time_input()
# main body starts here!
userInput = 0
while userInput != 4:
print_blanks()
userInput = int(input("Menu:\n1. Show all activity\n2. Add task\n3. Delete task\n4. Exits Program\n"))
if userInput == 1:
# show tasks
choice = input("do you want to sort the list[Y/N]? ")
show_act(choice)
input("press enter to continue...")
elif userInput == 2:
# add tasks
prio1 = ""
while prio1 != "LOW" and prio1 != "MEDIUM" and prio1 != "HIGH":
prio1 = input("set Priority [Low, Medium, High]: ").upper()
time1 = set_time_input()
des1 = input("Description:\n")
add_act(prio1, time1, des1)
elif userInput == 3:
# delete tasks
show_act("N")
try:
act_index = input("please chose activity to delete by time: ")
except TypeError:
print("input must be on table!")
break
del_act(act_index)
elif userInput == 4:
# exits task
print("thank you for using the program")
else:
print("Please re-enter again")