-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathqrc.py
136 lines (106 loc) · 3.99 KB
/
qrc.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
import qrcode #generating qr code
import cv2 #reading webcam
from datetime import datetime
import pyzbar.pyzbar as pyzbar #decoding
import time
from tkinter import messagebox
from database import *
from barcode import Code39 #generating barcode
def scanQR():
if sqlAccess(cur.execute("SELECT * FROM EMP;")) == []:
messagebox.showerror("DATABASE EMPTY", "No Employee has been registered yet!")
else:
# starting the webcam using opencv
cap = cv2.VideoCapture(0)
names=[]
#function for writing the data
def enterData(z):
if z in names:
pass
else:
flag = 0
if len(sqlAccess(cur.execute("SELECT * FROM EMP"))) >2:
emplid = sqlAccess(cur.execute("SELECT EMPID FROM EMP;"))
empid = []
for i in range(0,len(emplid)):
empid.append(emplid[i][0])
if z in empid:
flag = 1
elif z in sqlAccess(cur.execute("SELECT EMPID FROM EMP;"))[0][0]:
flag = 2
if flag == 1 or 2:
date = datetime.now().strftime("%d-%m-%Y")
t = datetime.now().strftime("%I:%M %p")
names.append(z)
print(z)
file = open(f"ATTENDANCE/attendance of {date}.txt","a")
z = z[2:]
z = str(z[:-1])
print(z)
naam = sqlAccess(cur.execute("SELECT NAME FROM EMP WHERE EMPID = ?",(z,)))[0][0]
print(naam)
att = f"{naam} on date {date} and time {t} is PRESENT\n\n"
file.write(att)
else:
messagebox.showerror("Attendance Failed", "NOT REGISTERED AS EMPLOYEE! CONTACT YOUR ADMIN!")
#function to check if the data is present or not
def checkData(data):
data=str(data)
if data in names:
messagebox.showinfo('Info', 'Already Present')
else:
#print(f"{str(len(names)+1)}- {data} - PRESENT")
enterData(data)
while True:
_, frame = cap.read()
decodedObjects = pyzbar.decode(frame)
for obj in decodedObjects:
checkData(obj.data)
time.sleep(1)
cv2.imshow("**Take Attendance** press C to close", frame)
#closing the program when s is pressed
if cv2.waitKey(1)& 0xFF == ord('c'):
cv2.destroyAllWindows()
break
def genQR(id,file):
img = qrcode.make(f"{id}")
img.save(f'id_gen//{file}.jpg')
def scanBar():
# starting the webcam using opencv
cap = cv2.VideoCapture(0)
barcodes=[]
def enterData(z):
if z in barcodes:
pass
else:
z = str(z)
#print(z)
z = z[2:]
z = int(z[:-2])
barcodes.append(z)
#print(barcodes)
#function to check if the data is present or not
def checkData(data):
data=str(data)
if data in barcodes:
pass
else:
enterData(data)
while True:
_, frame = cap.read()
decodedObjects = pyzbar.decode(frame)
for obj in decodedObjects:
checkData(obj.data)
time.sleep(1)
cv2.imshow("**Scan Barcode** Press C to close", frame)
#closing the program when c is pressed
if cv2.waitKey(1)& 0xFF == ord('c'):
cv2.destroyAllWindows()
break
return barcodes[0]
def genBar(code,product_name):
from barcode.writer import ImageWriter
my_code = Code39(code,writer= ImageWriter())
my_code.save(f"barcodes/{product_name}")
if __name__=="__main__":
pass