-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdata_access.py
37 lines (30 loc) · 971 Bytes
/
data_access.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
import sqlite3
import os
DB = None
def init():
if os.environ.get("DB_READY"):
return True
else:
try:
open("test.db", "rb").close()
global DB
DB = sqlite3.connect("test.db")
DB.execute('''CREATE TABLE REQUESTS
( req_id INT PRIMARY KEY NOT NULL
text TEXT NOT NULL,
scores TEXT);''')
os.environ["DB_READY"] = True
return True
except Exception as ex:
print ex
return False
def add_new_request(req_id, text):
try:
DB.execute("INSERT INTO REQUESTS(req_id,text) VALUES (?,?);"(req_id, text))
except Exception as ex:
print ex
def set_scores(req_id,scores):
try:
DB.execute("INSERT INTO REQUESTS(scores) VALUES (?) WHERE req_id LIKE ? ", (req_id, scores))
except Exception as ex:
print ex