-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdb_functions.py
261 lines (195 loc) · 5.82 KB
/
db_functions.py
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
import sqlite3
import os
def save_project_name(name):
conn = sqlite3.connect('main.db')
cur = conn.cursor()
cur.execute('''CREATE TABLE IF NOT EXISTS project_name (name TEXT)''')
conn.commit()
cur.execute('''INSERT INTO project_name (name) VALUES(?)''', (name,))
conn.commit()
cur.close()
conn.close()
def get_project_name():
conn = sqlite3.connect('main.db')
cur = conn.cursor()
qry = cur.execute('''SELECT name FROM project_name''')
item = qry.fetchone()[0]
cur.close()
conn.close()
return item
def new_task_info(name, blurb, count):
count = int(count)
conn = sqlite3.connect('main.db')
cur = conn.cursor()
cur.execute('''CREATE TABLE IF NOT EXISTS tasks (title TEXT,
description TEXT, time INTEGER, project_name TEXT)''')
# If a user is modifying an existing task this try statement will be used
try:
qry = cur.execute('''SELECT * FROM tasks WHERE title = (?)''', (name,))
info = qry.fetchone()[0]
cur.execute('''UPDATE tasks SET title = (?), description=(?),
time=(?) WHERE title = (?)''', (name, blurb, count, info))
conn.commit()
cur.close()
conn.close()
return True
except:
cur.execute('''INSERT INTO tasks (title, description, time)
VALUES(?,?,?)''', (name, blurb, count))
conn.commit()
cur.close()
conn.close()
return False
def start_new_project():
os.remove('main.db')
print("database removed")
def check_completed_names(text):
conn = sqlite3.connect('main.db')
cur = conn.cursor()
try:
qry = cur.execute('''SELECT * FROM completions WHERE title = (?)''',
(text,))
data = qry.fetchone()
if data == None:
result = False
else:
result = True
except:
result = False
cur.close()
conn.close()
return result
def add_completed_task(title, description, time, notes):
conn = sqlite3.connect("main.db")
cur = conn.cursor()
cur.execute('''CREATE TABLE IF NOT EXISTS completions (title TEXT,
description TEXT, time INTEGER, notes TEXT)''')
cur.execute('''INSERT INTO completions (title, description,
time, notes) VALUES (?,?,?,?)''',
(title, description, time, notes))
conn.commit()
cur.close()
conn.close()
return
def run_project_timer():
conn = sqlite3.connect('main.db')
cur = conn.cursor()
cur.execute('''CREATE TABLE IF NOT EXISTS project_time
(time INTEGER)''')
conn.commit()
qry = cur.execute('''SELECT * FROM project_time''')
qry = cur.fetchone()
# if statement used to catch the first time this func is run from program
if not qry:
print('not query')
cur.execute('''INSERT INTO project_time (time) VALUES (?)''',
(1,))
conn.commit()
cur.close()
conn.close()
return 1
new_time = qry[0] + 1
cur.execute('''UPDATE project_time SET time = (?)''', (new_time,))
conn.commit()
cur.close()
conn.close()
return new_time
def update_timer(new_time, task):
conn = sqlite3.connect('main.db')
cur = conn.cursor()
cur.execute('''SELECT time FROM tasks WHERE title = (?)''',
(task,))
cur.execute('''UPDATE tasks SET time = (?) WHERE title = (?)''',
(new_time, task))
conn.commit()
cur.execute('''SELECT time FROM tasks WHERE title = (?)''',
(task,))
cur.close()
conn.close()
def retrieve_project_time():
conn = sqlite3.connect('main.db')
cur = conn.cursor()
try:
qry = cur.execute('''SELECT * FROM project_time''')
info = qry.fetchone()[0]
except:
info = 0
cur.close()
conn.close()
return info
def retrieve_tasks():
conn = sqlite3.connect('main.db')
cur = conn.cursor()
info = None
try:
qry = cur.execute('''SELECT title, time FROM tasks''')
info = qry.fetchall()
except:
pass
cur.close()
conn.close()
return info
def retrieve_task_info(task):
conn = sqlite3.connect('main.db')
cur = conn.cursor()
qry = cur.execute('''SELECT * FROM tasks WHERE title = (?)''', (task,))
info = qry.fetchone()
cur.close()
conn.close()
return info
def retrieve_description(title):
conn = sqlite3.connect('main.db')
cur = conn.cursor()
info = None
try:
qry = cur.execute('''SELECT description FROM tasks WHERE title = (?)''',
(title,))
info = qry.fetchone()
except:
pass
cur.close()
conn.close()
return info
def retrieve_initial_time(title):
conn = sqlite3.connect('main.db')
cur = conn.cursor()
qry = cur.execute('''SELECT time FROM tasks WHERE title = (?)''',
(title,))
info = qry.fetchone()
cur.close()
conn.close()
return info
def retrieve_notes(title):
conn = sqlite3.connect('main.db')
cur = conn.cursor()
info = None
try:
qry = cur.execute('''SELECT notes FROM completions WHERE title = (?)''',
(title,))
info = qry.fetchone()
except:
pass
cur.close()
conn.close()
return info
def retrieve_completions():
conn = sqlite3.connect('main.db')
cur = conn.cursor()
try:
qry = cur.execute('''SELECT * FROM completions''')
info = qry.fetchall()
except:
info = False
pass
cur.close()
conn.close()
return info
def delete_task(task):
conn = sqlite3.connect('main.db')
cur = conn.cursor()
cur.execute('''DELETE FROM tasks WHERE title = (?)''',
(task,))
conn.commit()
cur.execute('''SELECT * FROM tasks''')
cur.close()
conn.close()