-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathEntryExitLog_Db.py
203 lines (153 loc) · 6.41 KB
/
EntryExitLog_Db.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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
#this is from other side for scanning purpose for entry andd exit
import SendingMailAtExit
import pyrebase, ast
import cv2
import pyzbar.pyzbar as pyzbars
import SendingMailAtEntry
firebaseConfig = {
'apiKey': "AIzaSyBFidAWIw-UggFx49xbXLunkXW5-_c1Ywo",
'authDomain': "entryexittagglogdb.firebaseapp.com",
'projectId': "entryexittagglogdb",
'storageBucket': "entryexittagglogdb.appspot.com",
'messagingSenderId': "898361353579",
'appId': "1:898361353579:web:924cc29e68e3522c80d82e",
'measurementId': "G-PWFZBQG312",
'databaseURL':'https://entryexittagglogdb-default-rtdb.firebaseio.com'
}
firebase = pyrebase.initialize_app(firebaseConfig)
db = firebase.database()
qr_values = ''
stud_usn = ''
stud_dict = ''
def entry_qr_db(stud_usn_passing,stud_key_db,stud_db_val):
print("came to insert into db")
#need to start codin from here
print(stud_usn_passing,stud_key_db,stud_db_val)
db.child(stud_usn_passing).child(stud_key_db).set(stud_db_val)
print("successfully inserted into DAtabse After scanning at Entry Time")
def exit_qr_db(stud_usn_passing,stud_key_db,stud_db_val):
print("came to insert into db")
#need to start codin from here
print(stud_usn_passing,stud_key_db,stud_db_val)
db.child(stud_usn_passing).child(stud_key_db).set(stud_db_val)
print("successfully inserted into DAtabse After scanning at Exit Time")
def scan_entry():
cap = cv2.VideoCapture(0)
while True:
_,frame = cap.read()
decodedObj = pyzbars.decode(frame)
for obj in decodedObj:
print(obj.data)
qr_values = obj.data
print(qr_values)
print(type(qr_values))
str1 = qr_values.decode('UTF-8')
#it is in string dictionary we have to convert to pure from of dictionary
print(str1)
print(type(str1))
#converting to dict
stud_dict = ast.literal_eval(str1) #ast is a converter
print("the converted dict is :"+str(stud_dict))
print(type(stud_dict))
print()
#extract the getting images
print(stud_dict.get("USN"))
stud_usn = stud_dict.get("USN")
print("Y i cant pass")
#extracting the key
print(stud_dict.get("Key"))
stud_key = stud_dict.get("Key")
#This is Seprate for Sending to the User about their report of Exiting!!
#extracting the email
print(stud_dict.get("emailid"))
stud_email = stud_dict.get("emailid")
#Extracting the Reason Time
print(stud_dict.get("reason"))
stud_reason = stud_dict.get("reason")
#Extracting the Time
stud_time = stud_dict.get("time*day")
#Extracting when they went out time
stud_Odate = stud_dict.get("Out*Date")
#Extracting the out date
stud_Otime = stud_dict.get("Out*Time")
#Extract Name
stud_name = stud_dict.get("Name")
print("Extraction Succesfull")
#inserting into db
entry_qr_db( stud_usn,stud_key,stud_dict)
print("Successful Now send to email")
# Now i have email id,reason,time,outtime,outdate,name so total 5 parameters
SendingMailAtEntry.sendmail(stud_name, stud_email, stud_time, stud_reason, stud_Otime, stud_Odate)
print("Went Successfullyy!!")
cv2.imshow("frames to scan QR Code",frame)
key = cv2.waitKey(1)
if(key == 10):
break
def scan_exit():
print("Came to Exit")
#need to start code from here
cap = cv2.VideoCapture(0)
while True:
_, frame = cap.read()
decodedObj = pyzbars.decode(frame)
for obj in decodedObj:
print(obj.data)
qr_values = obj.data
print(qr_values)
print(type(qr_values))
str1 = qr_values.decode('UTF-8')
# it is in string dictionary we have to convert to pure from of dictionary
print(str1)
print(type(str1))
# converting to dict
stud_dict = ast.literal_eval(str1)
print("the converted dict is :" + str(stud_dict))
print(type(stud_dict))
# extract the getting images
print(stud_dict.get("USN"))
stud_usn = stud_dict.get("USN")
print("Y i cant pass")
# extracting the key
print(stud_dict.get("Key"))
stud_key = stud_dict.get("Key")
# This is Seprate for Sending to the User about their report of Exiting!!
# extracting the email
print(stud_dict.get("emailid"))
stud_email = stud_dict.get("emailid")
# Extracting the Reason Time
print(stud_dict.get("reason"))
stud_reason = stud_dict.get("reason")
# Extracting the Time
stud_time = stud_dict.get("time*day")
# Extracting when they went out time
stud_Odate = stud_dict.get("Out*Date")
# Extracting the out date
stud_Otime = stud_dict.get("Out*Time")
# Extract Name
stud_name = stud_dict.get("Name")
#Extracting the in time
stud_InTime1 = stud_dict.get("In*Time")
#Extracting the in date
stud_InDate = stud_dict.get("In*Date")
print("Extraction Succesfull")
# inserting into db
exit_qr_db(stud_usn,stud_key, stud_dict)
print("Successful Now Sending to mail!!")
# Now i have email id,reason,time,outtime,outdate,name so total 5 parameters
SendingMailAtExit.sendmail(stud_name, stud_email, stud_time, stud_reason, stud_Otime, stud_Odate,
stud_InTime1, stud_InDate)
print("Went Successfullyy!!")
cv2.imshow("frames to scan QR code", frame)
key = cv2.waitKey(1)
if (key == 10):
break
def selection():
print("Select Your Operations:")
print("1.SCAN FOR Entry(i.e is Going out!!)")
print("2.SCAN FOR Exit(i.e is Coming in!!)")
ch = int(input("1 or 2 :"))
if(ch == 1 ):
scan_entry()
else:
scan_exit()
selection()