4
4
connect = sql .connect ('planner.db' )
5
5
cursor = connect .cursor ()
6
6
7
- cursor .execute ("CREATE TABLE IF NOT EXISTS tasks (task_id INTEGER PRIMARY KEY, task TEXT, type TEXT, time REAL)" )
7
+ cursor .execute ("CREATE TABLE IF NOT EXISTS tasks (task_id INTEGER PRIMARY KEY, task TEXT UNIQUE , type TEXT, time REAL)" )
8
8
9
9
def get_choice (max , phrase , do_phrase = True ):
10
10
choice = 0
@@ -26,17 +26,11 @@ def get_tasks():
26
26
cursor .execute ("SELECT * FROM tasks" )
27
27
return cursor .fetchall ()
28
28
29
- def display_tasks (tasks , numbers = True ):
30
- if numbers :
31
- print ('\n {:<5} {:<15} {:<15} {:<15}' .format ('ID' , 'Task' , 'Type' , 'Time' ))
32
- print ('{:<5} {:<15} {:<15} {:<15}' .format ('---' , '-----' , '-----' , '-----' ))
33
- for task in tasks :
34
- print ('{:<5} {:<15} {:<15} {:<15}' .format (task [0 ] + 1 , task [1 ], task [2 ], task [3 ]))
35
- else :
36
- print ('\n {:<15} {:<15} {:<15}' .format ('Task' , 'Type' , 'Time' ))
37
- print ('{:<15} {:<15} {:<15}' .format ('-----' , '-----' , '-----' ))
38
- for task in tasks :
39
- print ('{:<15} {:<15} {:<15}' .format (task [1 ], task [2 ], task [3 ]))
29
+ def display_tasks (tasks ):
30
+ print ('\n {:<15} {:<15} {:<15}' .format ('Task' , 'Type' , 'Time' ))
31
+ print ('{:<15} {:<15} {:<15}' .format ('-----' , '-----' , '-----' ))
32
+ for task in tasks :
33
+ print ('{:<15} {:<15} {:<15}' .format (task [1 ], task [2 ], task [3 ]))
40
34
41
35
print ('Welcome to your planner!' )
42
36
@@ -48,7 +42,7 @@ def display_tasks(tasks, numbers=True):
48
42
if choice == 1 :
49
43
#if user chooses choice 1, display all tasks, the task type, and the task time
50
44
tasks = get_tasks ()
51
- display_tasks (tasks , False )
45
+ display_tasks (tasks )
52
46
53
47
if choice == 2 :
54
48
# if user choose choice 2, display the choices for editing and allow for answer
@@ -61,29 +55,31 @@ def display_tasks(tasks, numbers=True):
61
55
while hours < 0 :
62
56
try :
63
57
hours = float (input ('Time to complete in hours: ' ))
58
+ if hours < 0 :
59
+ print ('\n Not a valid number.\n ' )
60
+ time .sleep (.5 )
64
61
except ValueError :
65
62
print ('\n Not a valid number.\n ' )
66
63
time .sleep (.5 )
67
64
tasks = get_tasks ()
68
- values = (len ( tasks ) , task , type , hours )
65
+ values = (None , task , type , hours )
69
66
cursor .execute ("INSERT INTO tasks VALUES (?, ?, ?, ?)" , values ) #insert the ID, and the inputs from the user to the database
70
67
connect .commit ()
71
68
elif choice == 2 :
72
69
tasks = get_tasks ()
73
70
display_tasks (tasks )
74
- choice = get_choice ( len ( tasks ), '\n Which number task would you like to edit?' )
75
- task_id = choice - 1
71
+ print ( '\n Which task would you like to edit?' )
72
+ edit = input ( '-> ' )
76
73
choice = get_choice (3 , '\n Would you like to edit:\n 1). Task\n 2). Type\n 3). Time' )
77
-
78
74
if choice == 1 :
79
75
task = input ('\n Task: ' )
80
- values = (task , task_id )
81
- cursor .execute ("UPDATE tasks SET task = ? WHERE task_id = ?" , values )
76
+ values = (task , edit )
77
+ cursor .execute ("UPDATE tasks SET task = ? WHERE task = ?" , values )
82
78
connect .commit ()
83
79
elif choice == 2 :
84
80
type = input ('\n Type of task: ' )
85
- values = (type , task_id )
86
- cursor .execute ("UPDATE tasks SET type = ? WHERE task_id = ?" , values )
81
+ values = (type , edit )
82
+ cursor .execute ("UPDATE tasks SET type = ? WHERE task = ?" , values )
87
83
connect .commit ()
88
84
elif choice == 3 :
89
85
choice = None
@@ -98,39 +94,27 @@ def display_tasks(tasks, numbers=True):
98
94
print ('\n Not a valid number.' )
99
95
time .sleep (.5 )
100
96
hours = - 1
101
- values = (hours , task_id )
102
- cursor .execute ("UPDATE tasks SET time = ? WHERE task_id = ?" , values )
97
+ values = (hours , edit )
98
+ cursor .execute ("UPDATE tasks SET time = ? WHERE task = ?" , values )
103
99
connect .commit ()
104
-
105
-
106
-
107
100
elif choice == 3 :
108
101
tasks = get_tasks ()
109
102
choice = 0
110
- while choice < 1 or choice > len (tasks ):
111
- display_tasks (tasks )
112
- choice = get_choice (len (tasks ), '\n Which number task would you like to delete?' )
113
- task_id = choice - 1
114
- values = (task_id ,)
115
- cursor .execute ("DELETE FROM tasks WHERE task_id = ?" , values )
103
+ display_tasks (tasks )
104
+ print ('\n Which task would you like to delete?' )
105
+ choice = input ('-> ' )
106
+ values = (choice ,)
107
+ cursor .execute ("DELETE FROM tasks WHERE task = ?" , values )
116
108
connect .commit ()
117
- tasks = get_tasks ()
118
- for task in tasks :
119
- if task [0 ] > task_id :
120
- values = (task [0 ] - 1 , task_id )
121
- cursor .execute ("UPDATE tasks SET task_id = ? WHERE task_id = ?" , values )
122
- connect .commit ()
123
- choice = None
124
109
125
-
126
-
127
-
128
110
elif choice == 4 :
129
- verify = input ('\n Are you sure you want to reset the planner (y/n)? ' )
111
+ verify = input ('\n Are you sure you want to reset the planner (y/n)? ' ).lower ()
112
+ if verify == 'y' :
113
+ cursor .execute ('DELETE FROM tasks' )
114
+ else :
115
+ pass
130
116
elif choice == 5 :
131
117
pass
132
- else :
133
- pass
134
118
135
119
136
120
0 commit comments