-
Notifications
You must be signed in to change notification settings - Fork 2
/
qr_validator.py
86 lines (68 loc) · 2.32 KB
/
qr_validator.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
import cv2
from pyzbar.pyzbar import decode
import requests
import numpy as np
import mysql.connector as sql
import json
db = sql.connect(
host="sql6.freesqldatabase.com",
user="sql6514192",
passwd="cPeZlsijGB",
database="sql6514192",
port="3306"
)
def execute(query):
try:
cursor = db.cursor()
cursor.execute(query)
res = cursor.fetchall()
db.commit()
return res
except sql.Error as err:
print(err)
return -1
def verify_qr(purpose):
url = "http://192.168.43.1:8080/shot.jpg"
while True:
raw_image = requests.get(url)
img_arr = np.array(bytearray(raw_image.content), dtype=np.uint8)
img = cv2.imdecode(img_arr, -1)
for barcode in decode(img):
myData = barcode.data.decode('utf-8')
query = f"""
SELECT *
FROM Student
WHERE shahash = "{myData}";
"""
res = execute(query)
if len(res) > 0:
if purpose == 1:
if res[0][2] == 0:
print("\n\t", res[0][0], "Authorizing for Entry.")
query = f"""
UPDATE Student SET entrystatus = {1}
WHERE shahash = "{myData}";
"""
execute(query)
else:
print(res[0][0], "Already Authorized for Entry.")
if purpose == 2:
if res[0][3] != 0:
print("\n\t", res[0][0], "Authorizing for Food.")
query = f"""
UPDATE Student SET foodstatus = {1}
WHERE shahash = "{myData}";
"""
execute(query)
else:
print(res[0][0], "Already Authorized for Food.")
else:
print("Un-Authorized")
cv2.waitKey(1000)
def read_data():
file = open('data.json')
data = json.load(file)
return data
if __name__ == "__main__":
verify_qr(1) # for entry
# verify_qr(2) # for food