-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdb_handler.py
More file actions
75 lines (53 loc) · 2.07 KB
/
db_handler.py
File metadata and controls
75 lines (53 loc) · 2.07 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
import sqlite3
def mb_db(cpu, price_max, price_min):
socket = cpu[8]
con = sqlite3.connect('pcdb.db')
cur = con.cursor()
cur.execute(f"SELECT * FROM motherboard_parameters "
f"WHERE (price <= {price_max}) "
f"AND (price >= {price_min}) "
f"AND (socket = '{socket}')")
selection = cur.fetchall()
return selection
def psu_db(price_max, price_min):
con = sqlite3.connect('pcdb.db')
cur = con.cursor()
cur.execute(f'SELECT * FROM psu_parameters '
f'WHERE (price <= {price_max})'
f'AND (price >= {price_min})')
selection = cur.fetchall()
return selection
def db_sel(table, price_max, price_min):
con = sqlite3.connect('pcdb.db')
cur = con.cursor()
selection = None
if table == "cpu":
cur.execute(f'SELECT * FROM cpu_parameters '
f'WHERE (price <= {price_max})'
f'AND (price >= {price_min})')
selection = cur.fetchall()
if table == "gpu":
cur.execute(f'SELECT * FROM gpu_parametrs '
f'WHERE (price <= {price_max})'
f'AND (price >= {price_min})')
selection = cur.fetchall()
if table == "psd":
cur.execute(f'SELECT * FROM storage_parameters '
f'WHERE (price <= {price_max})'
f'AND (price >= {price_min})')
selection = cur.fetchall()
if table == "ram":
cur.execute(f'SELECT * FROM ram_parameters '
f'WHERE (price <= {price_max})'
f'AND (price >= {price_min})')
selection = cur.fetchall()
return selection
def db_pc_list(pcl):
price = pcl[0][-1] + pcl[1][-1] + pcl[2][-1] + pcl[3][-1] + pcl[4][-1] + pcl[5][-1]
con = sqlite3.connect("pcdb.db")
cur = con.cursor()
cur.execute("INSERT INTO pc (cpu, gpu, motherboard, psd, ram, ps, price) "
"VALUES (?, ?, ?, ?, ?, ?, ?)",
(pcl[0][0], pcl[1][0], pcl[2][0], pcl[3][0], pcl[4][0], pcl[5][0], price))
con.commit()
return price