Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f1d759e

Browse files
authored
Merge pull request #3 from jakeard/work
finished UI, beginning SQL commands
2 parents 150c15e + 3c83492 commit f1d759e

File tree

2 files changed

+29
-45
lines changed

2 files changed

+29
-45
lines changed

‎planner.db‎

12 KB
Binary file not shown.

‎planner.py‎

Lines changed: 29 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
connect = sql.connect('planner.db')
55
cursor = connect.cursor()
66

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)")
88

99
def get_choice(max, phrase, do_phrase=True):
1010
choice = 0
@@ -26,17 +26,11 @@ def get_tasks():
2626
cursor.execute("SELECT * FROM tasks")
2727
return cursor.fetchall()
2828

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]))
4034

4135
print('Welcome to your planner!')
4236

@@ -48,7 +42,7 @@ def display_tasks(tasks, numbers=True):
4842
if choice == 1:
4943
#if user chooses choice 1, display all tasks, the task type, and the task time
5044
tasks = get_tasks()
51-
display_tasks(tasks, False)
45+
display_tasks(tasks)
5246

5347
if choice == 2:
5448
# if user choose choice 2, display the choices for editing and allow for answer
@@ -61,29 +55,31 @@ def display_tasks(tasks, numbers=True):
6155
while hours < 0:
6256
try:
6357
hours = float(input('Time to complete in hours: '))
58+
if hours < 0:
59+
print('\nNot a valid number.\n')
60+
time.sleep(.5)
6461
except ValueError:
6562
print('\nNot a valid number.\n')
6663
time.sleep(.5)
6764
tasks = get_tasks()
68-
values = (len(tasks), task, type, hours)
65+
values = (None, task, type, hours)
6966
cursor.execute("INSERT INTO tasks VALUES (?, ?, ?, ?)", values) #insert the ID, and the inputs from the user to the database
7067
connect.commit()
7168
elif choice == 2:
7269
tasks = get_tasks()
7370
display_tasks(tasks)
74-
choice=get_choice(len(tasks), '\nWhich number task would you like to edit?')
75-
task_id = choice-1
71+
print('\nWhich task would you like to edit?')
72+
edit = input('-> ')
7673
choice = get_choice(3, '\nWould you like to edit:\n1). Task\n2). Type\n3). Time')
77-
7874
if choice == 1:
7975
task = input('\nTask: ')
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)
8278
connect.commit()
8379
elif choice == 2:
8480
type = input('\nType 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)
8783
connect.commit()
8884
elif choice == 3:
8985
choice = None
@@ -98,39 +94,27 @@ def display_tasks(tasks, numbers=True):
9894
print('\nNot a valid number.')
9995
time.sleep(.5)
10096
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)
10399
connect.commit()
104-
105-
106-
107100
elif choice == 3:
108101
tasks = get_tasks()
109102
choice = 0
110-
while choice < 1 or choice > len(tasks):
111-
display_tasks(tasks)
112-
choice = get_choice(len(tasks), '\nWhich 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('\nWhich task would you like to delete?')
105+
choice = input('-> ')
106+
values = (choice,)
107+
cursor.execute("DELETE FROM tasks WHERE task = ?", values)
116108
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
124109

125-
126-
127-
128110
elif choice == 4:
129-
verify = input('\nAre you sure you want to reset the planner (y/n)? ')
111+
verify = input('\nAre 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
130116
elif choice == 5:
131117
pass
132-
else:
133-
pass
134118

135119

136120

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /