-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathdatabase.py
85 lines (71 loc) · 2.12 KB
/
database.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
import sqlite3
import os
def create():
db = sqlite3.connect('realtest.db')
c = db.cursor()
c.execute("""CREATE TABLE realtest(
numPlate text,
timeStamp text,
name text,
address text,
errCode integer,
photo blob,
platePic blob
)""")
db.commit()
db.close()
def insert(numPlate, name, address, photo, time, errcode, platePic):
cwd = os.getcwd()
parDir = cwd.replace('tkinterUI', '')
parDir = parDir.replace('\\', '/')
db = sqlite3.connect(f'{parDir}realtest.db')
c = db.cursor()
c.execute(
f"INSERT INTO realtest VALUES ('{numPlate}','{time}','{name}','{address}',{errcode},?,?)",
(sqlite3.Binary(photo), sqlite3.Binary(platePic)))
db.commit()
db.close()
def getDb():
cwd = os.getcwd()
print(cwd)
db = sqlite3.connect(f'{cwd}\\realtest.db')
c = db.cursor()
c.execute("SELECT rowid,* FROM realtest")
list = c.fetchall()
db.commit()
db.close()
return list
# deprecated
def image_to_bin():
cwd = os.getcwd()
with open(f'{cwd}\\Resources\\img.png', 'rb') as file:
binary0 = file.read()
with open(f'{cwd}\\Resources\\IndImg.jfif', 'rb') as file:
binary1 = file.read()
return binary0, binary1
# deprecated
def bin_to_image(binary):
cwd = os.getcwd()
with open(f'{cwd}\\Resources\\tempPhoto.png', 'wb') as file:
file.write(binary[0])
with open(f'{cwd}\\Resources\\tempPlate.png', 'wb') as file:
file.write(binary[1])
# print(errorCodes.decode(3))
# create()
# b0, b1 = image_to_bin()
# for i in range(20):
# insert(
# numPlate='MH14DT2661',
# name=f'MARUTI SXI GREEN VXI',
# address='PIMPRI-CHINCHWAD, Maharashtra',
# photo=b0,
# time=(datetime.now() + timedelta(days=i, minutes=i)).strftime("%H:%M:%S | %d-%m-%Y"),
# errcode=i % 8,
# platePic=b1
# )
# print(show())
# cwd = os.getcwd() # Get the current working directory (cwd)
# files = os.listdir(cwd) # Get all the files in that directory
# print("Files in %r: %s" % (cwd, files))
# par_dir = os.path.dirname(cwd)
# print("Parent directory", par_dir)