-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbare_bones.py
297 lines (251 loc) · 9.62 KB
/
bare_bones.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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
from datetime import datetime
import sqlite3
now = datetime.now()
CREATE_GROCERIES = "CREATE TABLE IF NOT EXISTS groceries (id INTEGER PRIMARY KEY,good TEXT, price INTEGER, date DATE);"
CREATE_HOUSEHOLD = "CREATE TABLE IF NOT EXISTS household (id INTEGER PRIMARY KEY,good TEXT, price INTEGER, date DATE);"
CREATE_ENTERTAINMENT = "CREATE TABLE IF NOT EXISTS entertainment (id INTEGER PRIMARY KEY,good TEXT, price INTEGER, " \
"date DATE);"
CREATE_OTHER = "CREATE TABLE IF NOT EXISTS other (id INTEGER PRIMARY KEY,good TEXT, price INTEGER, date DATE);"
INSERT_GROCERIES = "INSERT INTO groceries (good, price, date) VALUES(?,?,?);"
INSERT_HOUSEHOLD = "INSERT INTO household (good, price, date) VALUES(?,?,?);"
INSERT_ENTERTAINMENT = "INSERT INTO entertainment (good, price, date) VALUES(?,?,?);"
INSERT_OTHER = "INSERT INTO other (good, price, date) VALUES(?,?,?);"
SELECT_ALL_GROCERIES = "SELECT * FROM groceries;"
SELECT_ALL_HOUSEHOLD = "SELECT * FROM household;"
SELECT_ALL_ENTERTAINMENT = "SELECT * FROM entertainment;"
SELECT_ALL_OTHER = "SELECT * FROM other;"
SELECT_GROCERIES = "SELECT * FROM groceries WHERE good = ?;"
SELECT_HOUSEHOLD = "SELECT * FROM household WHERE good = ?;"
SELECT_ENTERTAINMENT = "SELECT * FROM entertainment WHERE good = ?;"
SELECT_OTHER = "SELECT * FROM other WHERE good = ?;"
DELETE_GROCERIES = "DELETE FROM groceries WHERE good = ? AND price = ?;"
DELETE_HOUSEHOLD = "DELETE FROM household WHERE good = ? AND price = ?;"
DELETE_ENTERTAINMENT = "DELETE FROM entertainment WHERE good = ? AND price = ?;"
DELETE_OTHER = "DELETE FROM other WHERE good = ? AND price = ?;"
def create_grocery_table():
conn = sqlite3.connect('data.db')
with conn:
return conn.execute(CREATE_GROCERIES)
def create_entertainment_table():
conn = sqlite3.connect('data.db')
with conn:
return conn.execute(CREATE_ENTERTAINMENT)
def create_household_table():
conn = sqlite3.connect('data.db')
with conn:
return conn.execute(CREATE_HOUSEHOLD)
def create_other_table():
conn = sqlite3.connect('data.db')
with conn:
return conn.execute(CREATE_OTHER)
def insert_groceries(good, price, date):
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(INSERT_GROCERIES, (good, price, date))
conn.commit()
def insert_entertainment(good, price, date):
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(INSERT_ENTERTAINMENT, (good, price, date))
conn.commit()
def insert_household(good, price, date):
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(INSERT_HOUSEHOLD, (good, price, date))
conn.commit()
def insert_other(good, price, date):
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(INSERT_OTHER, (good, price, date))
conn.commit()
def select_all_groceries():
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(SELECT_ALL_GROCERIES)
print_list = c.fetchall()
c.close()
output = ''
for x in print_list:
output = output + str(x[1]) + ' ' + str(x[2]) + ' ' + ' ' + str(x[3]) + '\n'
return output
def select_all_entertainment():
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(SELECT_ALL_ENTERTAINMENT)
print_list = c.fetchall()
c.close()
output = ''
for x in print_list:
output = output + str(x[1]) + ' ' + str(x[2]) + ' ' + ' ' + str(x[3]) + '\n'
return output
def select_all_household():
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(SELECT_ALL_HOUSEHOLD)
print_list = c.fetchall()
c.close()
output = ''
for x in print_list:
output = output + str(x[1]) + ' ' + str(x[2]) + ' ' + ' ' + str(x[3]) + '\n'
return output
def select_all_other():
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(SELECT_ALL_OTHER)
print_list = c.fetchall()
c.close()
output = ''
for x in print_list:
output = output + str(x[1]) + ' ' + str(x[2]) + ' ' + ' ' + str(x[3]) + '\n'
return output
def select_grocery(good):
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(SELECT_GROCERIES, (good,))
print_list = c.fetchall()
c.close()
output = ''
for x in print_list:
output = output + str(x[1]) + ' ' + str(x[2]) + ' ' + ' ' + str(x[3]) + '\n'
return output
def select_entertainment(good):
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(SELECT_ENTERTAINMENT, (good,))
print_list = c.fetchall()
c.close()
output = ''
for x in print_list:
output = output + str(x[1]) + ' ' + str(x[2]) + ' ' + ' ' + str(x[3]) + '\n'
return output
def select_household(good):
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(SELECT_HOUSEHOLD, (good,))
print_list = c.fetchall()
c.close()
output = ''
for x in print_list:
output = output + str(x[1]) + ' ' + str(x[2]) + ' ' + ' ' + str(x[3]) + '\n'
return output
def select_other(good):
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(SELECT_OTHER, (good,))
print_list = c.fetchall()
c.close()
output = ''
for x in print_list:
output = output + str(x[1]) + ' ' + str(x[2]) + ' ' + ' ' + str(x[3]) + '\n'
return output
def delete_grocery(good, price):
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(DELETE_GROCERIES, (good, price))
conn.commit()
c.close()
def delete_entertainment(good, price):
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(DELETE_ENTERTAINMENT, (good, price))
conn.commit()
c.close()
def delete_household(good, price):
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(DELETE_HOUSEHOLD, (good, price))
conn.commit()
c.close()
def delete_other(good, price):
conn = sqlite3.connect('data.db')
with conn:
c = conn.cursor()
c.execute(DELETE_OTHER, (good, price))
conn.commit()
c.close()
# -------------main-------------------------------------------
# only needs to run once
# create_grocery_table()
# create_other_table()
# create_household_table()
# create_entertainment_table()
# to insert
enter=str(input('Would you like to enter an item?\n'))
while enter == 'yes':
type_item=str(input("What type of item is this?\n"))
item=str(input('Input the item name\n'))
cost=int(input('Input the item price\n'))
if type_item=='grocery':
insert_groceries(item, cost, now)
elif type_item=='entertainment':
insert_entertainment(item, cost, now)
elif type_item == 'household':
insert_household(item, cost, now)
elif type_item == 'other':
insert_other(item, cost, now)
enter=str(input('Would you like to enter another item?\n'))
# to print entire table
to_print = str(input("Would you like to print a table?\n"))
while to_print == 'yes':
select_table = str(input("What table would you like to print?\n"))
if select_table=='grocery':
print (select_all_groceries())
elif select_table=='entertainment':
print (select_all_entertainment())
elif select_table == 'household':
print (select_all_household())
elif select_table == 'other':
print (select_all_other())
to_print = str(input("Would you like to print another table?\n"))
# to print specific items
item_print = str(input("Would you like to print a certain item?\n"))
while item_print == 'yes':
select_table = str(input("From what table would you like to print?\n"))
select_item = str(input("What is the name of the item?\n"))
if select_table=='grocery':
print (select_grocery(select_item))
elif select_table=='entertainment':
print (select_entertainment(select_item))
elif select_table == 'household':
print (select_household(select_item))
elif select_table == 'other':
print (select_other(select_item))
item_print = str(input("Would you like to print another certain item?\n"))
# to delete specific item
item_delete = str(input("Would you like to delete an item?\n"))
while item_delete == 'yes':
select_table = str(input("From what table would you like to delete?\n"))
select_item_delete = str(input("What is the name of the item?\n"))
select_cost = str(input("What is the cost of the item?\n"))
if select_table=='grocery':
delete_grocery(select_item_delete, select_cost)
print ("item deleted, here is the new table\n")
print(select_all_groceries())
elif select_table=='entertainment':
delete_entertainment(select_item_delete, select_cost)
print("item deleted, here is the new table\n")
print(select_all_entertainment())
elif select_table == 'household':
delete_household(select_item_delete, select_cost)
print("item deleted, here is the new table\n")
print(select_all_household())
elif select_table == 'other':
delete_other(select_item_delete, select_cost)
print("item deleted, here is the new table\n")
print(select_all_other())
item_delete = str(input("Would you like to delete another item?\n"))