-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStappAot.py
663 lines (541 loc) · 29.5 KB
/
StappAot.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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
# Importing mandatory Dependencies
import streamlit as st, mysql.connector, cv2, os, face_recognition, time, re, sys
from PIL.Image import Image
st.title("Welcome")
# ---------------------------Subject Config------------------------------
subject_ID = ['subject1', 'subject2', 'subject3', 'subject4', 'subject5']
subject_config = ['MTH1001', 'CSE1001', 'EET1001', 'CHM1001', 'ENG1001']
# ---------------------------Subject Config------------------------------
# Navigation toolbar to go to pages
add_selectbox = st.sidebar.selectbox(
"NAVIGATION", # Title of sidebar
(
"Student Registration", "Faculty Registration", "Student Dashboard", "Faculty Dashboard", "Attendance Capture Tool"
)
# List of all options in sidebar
)
# ----------Creates a temporary folder----------
def CreateTempDir():
k = os.path.exists("temp")
if not k:
os.mkdir("temp")
# ----------------------------------------------
CreateTempDir()
# -----------------------Validate Email, Name, RegistrationID---------------------------
def email_check(email):
regex = '^[a-z0-9]+[\._]?[a-z0-9]+[@](\w+[.]\w{2,3}$)|(\w+[.]\w+[.]\w{2,3}$)'
if (re.search(regex, email)):
return True
else:
return False
def name_check(name):
regex='^[A-Za-z\s]+$'
if(re.search(regex,name)):
return True
else:
return False
def reg_check(reg):
regex='^[0-9]+$'
if(re.search(regex,reg)):
return True
else:
return False
# --------------------------------------------------------------------------------------
# ++++++++++++++++++++++++++++++++STUDENT REGISTRATION++++++++++++++++++++++++++++++++++
if add_selectbox == "Student Registration":
st.header("Student Registration")
# ---------------------------------Input fields-------------------------------------
Name = st.text_input("Name")
Email = st.text_input("Email")
reg = st.text_input("Registration Number")
password = st.text_input("Password", type="password")
password_check = st.text_input("Re enter Password", type="password")
if password != password_check: # Check whether the entered passwords match
st.warning("Passwords don't match")
# ------------------------------Email Verification----------------------------------
import pyrebase, time, streamlit as st
firebaseConfig = {
'apiKey': "AIzaSyAltyq3D5_TW8GluZ4goEBmwP2kGD41vY8",
'authDomain': "attendancesystem-1c820.firebaseapp.com",
'databaseURL': "https://attendancesystem-1c820-default-rtdb.firebaseio.com",
'projectId': "attendancesystem-1c820",
'storageBucket': "attendancesystem-1c820.appspot.com",
'messagingSenderId': "1064805715401",
'appId': "1:1064805715401:web:c2d8aab5ca364f12022c18",
'measurementId': "G-5TFT24ZJ55"
};
# auth.delete_user_account(user['idToken']) ---------A code snippet
firebase = pyrebase.initialize_app(firebaseConfig)
auth = firebase.auth()
@st.cache(suppress_st_warning=True)
def once():
email =Email
password = password_check
if (email != None and password != None):
user = auth.create_user_with_email_and_password(email, password)
st.info('Verification link sent to your email')
auth.send_email_verification(user['idToken'])
return user
try:
once()
except:
pass
def isemailverified():
user = once()
k = auth.get_account_info(user['idToken'])
verify_status = ((k['users'])[0])['emailVerified']
return verify_status # Return True or False
# st.write('You need to verify your email please check your inbox. ')
v = st.button('I agree that I\'ve verified my email')
if (v == True):
while (isemailverified() != True):
st.write('Sorry, you haven\'t verified your email, Please verify\n and wait ')
time.sleep(7)
if (isemailverified()):
st.success('You have successfully verified your email')
#-----------------------------------------------------------------------------------
known_img = st.file_uploader("Upload Image", type=["png", "jpg", "jpeg"])
#----------------------------------- Input fields-----------------------------------
if st.button("Submit") and password == password_check and isemailverified():
if not name_check(Name):
st.warning("Invalid Name")
sys.exit()
elif not email_check(Email):
st.warning("Invalid Email")
sys.exit()
elif not reg_check(reg):
st.warning("Invalid Registration ID")
sys.exit()
elif not known_img:
st.warning("Input an image")
sys.exit()
elif not password:
st.warning("Password must be set")
sys.exit()
else:
st.balloons()
# ---------Convert digital data to binary format----------
def convertToBinaryData(filename):
with open(filename, 'rb') as file:
binaryData = file.read()
return binaryData
# --------------------------------------------------------
# --------------------------------------------SQL Code to insert data--------------------------------------------
def insertBLOB(reg_num, Name, Email, Photo, password):
mydb = mysql.connector.connect(host="sql6.freemysqlhosting.net", database="sql6409330", user="sql6409330", password="dvjW6YhuvB")
my_cursor = mydb.cursor()
sql_insert_blob_query = "INSERT INTO registration (Reg, NAME, EMAIL, Photo, password) VALUES (%s,%s,%s,%s,%s)"
converted_picture = convertToBinaryData(Photo)
# Convert data into tuple format
insert_blob_tuple = (reg_num, Name, Email, converted_picture, password)
result = my_cursor.execute(sql_insert_blob_query, insert_blob_tuple)
mydb.commit()
print("Image inserted successfully as a BLOB into students table", result)
# --------------------------------------------SQL Code to Insert Data--------------------------------------------
# --------- Pass the uploaded file through streamlit to SQL----------------
def save_uploadedfile(uploadedfile):
with open(os.path.join("temp", uploadedfile.name), "wb") as f:
f.write(uploadedfile.getbuffer()) # Writes the file to directory Local
# Calls function to insert the photo and details into SQL
insertBLOB(reg, Name, Email, 'temp/{}'.format(uploadedfile.name), password)
return st.success("Successfully Registered")
# -------------------------------------------------------------------------
# ---------------------------------------------------------------------------
if (known_img != None):
save_uploadedfile(known_img)
# ++++++++++++++++++++FACULTY REGISTRATION+++++++++++++++++++++++++++++++
elif add_selectbox == "Faculty Registration":
st.header("Faculty Registration")
# ------------Input fields--------------------------------------
Name = st.text_input("Name")
Email = st.text_input("Email")
reg = st.text_input("Enter Faculty ID")
password = st.text_input("Password", type="password")
password_check = st.text_input("Re enter Password", type="password")
if password != password_check: # Checks if entered passwords match
st.warning("Passwords don't match")
classID = st.selectbox("Select your subject", subject_config)
auth = st.text_input("Enter Authorisation Code",type='password')
# -------------Input fields--------------------------------------
if (st.button("Submit") == True) and password == password_check:
idx = subject_config.index(classID)
classID = subject_ID[idx]
if not name_check(Name):
st.warning("Invalid Name")
sys.exit()
elif not email_check(Email):
st.warning("Invalid Email")
sys.exit()
elif not reg_check(reg):
st.warning("Invalid Faculty ID")
sys.exit()
elif not password:
st.warning("Password must be set")
sys.exit()
elif not auth:
st.warning("Enter the auth code")
sys.exit()
# -------------------------------SQL Code for faculty registration--------------------------------------------
def facultyregistration(Reg, Name, Email, Password, Subject):
mydb = mysql.connector.connect(host="sql6.freemysqlhosting.net", database="sql6409330", user="sql6409330", password="dvjW6YhuvB")
my_cursor = mydb.cursor()
sql_insert_blob_query = "INSERT INTO facultyreg (Reg, Name, Email,Password, Subject) VALUES (%s,%s,%s,%s,%s)"
insert_blob_tuple = (Reg, Name, Email, Password, Subject)
result = my_cursor.execute(sql_insert_blob_query, insert_blob_tuple)
mydb.commit()
# -------------------------------SQL Code for faculty registration-------------------------------------------
if(auth=='1020SOA'):
facultyregistration(reg, Name, Email, password, classID)
st.success("You are registered")
st.balloons()
# ++++++++++++++++++++ STUDENT DASHBOARD ++++++++++++++++++++++++++++++++
elif add_selectbox == "Student Dashboard":
st.header("Student Dashboard")
# ------------Input fields--------------------------------------
reg = st.text_input("Enter your registrationID")
password = st.text_input("Enter your password", type="password")
classID = st.selectbox("Select your subject", subject_config)
# ------------Input fields--------------------------------------
# --------- Extract password from student registration database-------------------
def password_validate(password):
connection = mysql.connector.connect(host="sql6.freemysqlhosting.net", database="sql6409330", user="sql6409330", password="dvjW6YhuvB")
cursor = connection.cursor()
sql_validate = "select password FROM registration where Reg={}".format(reg)
cursor.execute(sql_validate)
result = cursor.fetchall()
return result[0][0]
# -------------Extract password from student registration database-----------------
# --------------Extract student name from registration database-------------------------------------------
def findstudent(reg):
connection = mysql.connector.connect(host="sql6.freemysqlhosting.net", database="sql6409330", user="sql6409330", password="dvjW6YhuvB")
cursor = connection.cursor()
sql_validate = "select NAME FROM registration where Reg={}".format(reg)
cursor.execute(sql_validate)
result = cursor.fetchall()
st.write("The details are")
for x in result:
st.write("Name:", x[0])
# -------------Extract student name from registration database-------------------------------------------
# --------------Find attendance for a given reg no. -----------------------------------------------------
def findattendance1(reg, subject_num):
connection = mysql.connector.connect(host="sql6.freemysqlhosting.net", database="sql6409330", user="sql6409330", password="dvjW6YhuvB")
cursor = connection.cursor()
sql_attendance_subject = "select * from `{subject}` where reg={registration}".format(subject=subject_num,
registration=reg)
cursor.execute(sql_attendance_subject)
result = cursor.fetchall()
st.write("Attendance for:", classID)
count = 0;
total_present = 0;
# print(result[0][1])
for k in result[0]:
count += 1
if (k == '1'):
total_present += 1
st.write("Total classes", count - 1)
st.write("Total present", total_present)
st.write("Attendance Percentage", round((total_present / (count - 1) * 100), 2))
# -----------Find attendance for a given reg no. ---------------------------------------------------------
if st.button("Submit") == True:
if password == password_validate(reg): # Checks whether the entered password matches
st.success("Successfully Logged In")
findstudent(reg) # Extracts student's name from database
idx = subject_config.index(classID) # Maps subject number to subject CODE
classID_mapped = subject_ID[idx]
findattendance1(reg, classID_mapped) # Finds attendance for a student
else:
st.error("Incorrect RegID or Password")
# ++++++++++++++++++++ FACULTY DASHBOARD ++++++++++++++++++++++++++++++++
elif add_selectbox == "Faculty Dashboard":
st.header("Faculty Dashboard")
reg = st.text_input("Enter your Faculty ID")
password = st.text_input("Enter your password", type="password")
# ----------Coverts subject1 to MTH1001-------------------------------
def subject_mapping(sub):
idx = subject_ID.index(sub)
return subject_config[idx]
# -----------------------------------------------------------------------
# -----------------Validate Password------------------------------------------------------------------
def password_validate(password):
connection = mysql.connector.connect(host="sql6.freemysqlhosting.net", database="sql6409330", user="sql6409330", password="dvjW6YhuvB")
cursor = connection.cursor()
sql_validate = "select Password FROM facultyreg where Reg={}".format(reg)
cursor.execute(sql_validate)
result = cursor.fetchall()
return result[0][0]
# -----------------------------------------------------------------------------------------------------
# ----------------------Find Student Name--------------------------------------------------------------
def findstudent(reg):
connection = mysql.connector.connect(host="sql6.freemysqlhosting.net", database="sql6409330", user="sql6409330", password="dvjW6YhuvB")
cursor = connection.cursor()
sql_validate = "select NAME FROM registration where Reg={}".format(reg)
cursor.execute(sql_validate)
result = cursor.fetchall()
# st.write("The details are")
for x in result:
return x[0]
# -------------------------------------------------------------------------------------------------------
# -------------------------------Finding Faculty and their subject---------------------------------------
def find_faculty_and_subject(reg):
connection = mysql.connector.connect(host="sql6.freemysqlhosting.net", database="sql6409330", user="sql6409330", password="dvjW6YhuvB")
cursor = connection.cursor()
sql_validate = "select Name, Subject FROM facultyreg where Reg={}".format(reg)
cursor.execute(sql_validate)
result = cursor.fetchall()
st.write("The details are")
for x in result:
st.write("Name:", x[0])
st.write("Subject:", subject_mapping(x[1]))
return x[1]
# This function prints faculty name and subject. It returns subject_number
# --------------------------------------------------------------------------------------------------------
# ----------------------------Find All students' attendance-----------------------------------------------
def findattendance(subject_num):
connection = mysql.connector.connect(host="sql6.freemysqlhosting.net", database="sql6409330", user="sql6409330", password="dvjW6YhuvB")
cursor = connection.cursor()
sql_attendance_subject = "select * from `{subject}`".format(subject=subject_num)
cursor.execute(sql_attendance_subject)
result = cursor.fetchall()
st.write("Attendance for:", )
for entry in result:
st.write(findstudent(entry[0])) # Shows student name
findattendancepercent(entry[0], subject_num) # Finds attendance percent
# ----------------------------------------------------------------------------------------------------------
# ------------------------Find attendance for each student with percentage-------------------------------
def findattendancepercent(reg, subject_num):
connection = mysql.connector.connect(host="sql6.freemysqlhosting.net", database="sql6409330", user="sql6409330", password="dvjW6YhuvB")
cursor = connection.cursor()
sql_attendance_subject = "select * from `{subject}` where reg={registration}".format(subject=subject_num,
registration=reg)
cursor.execute(sql_attendance_subject)
result = cursor.fetchall()
count = 0;
total_present = 0
for k in result[0]:
count += 1
if (k == '1'):
total_present += 1
st.write("Present", total_present, "out of", count - 1, "classes", "Attendance Percentage",
round((total_present / (count - 1) * 100), 2))
# -----------------------Find attendance for each student with percentage---------------------------
# Calls another function findattendance with input as subject_encoded
def show_All_attendance():
findattendance(subject_encoded)
if st.button("Submit"):
if password == password_validate(reg):
st.success("Successfully Logged In")
subject_encoded = find_faculty_and_subject(reg) # Subject encoded stores the subject of a given faculty
show_All_attendance()
else:
st.error("Incorrect RegID or Password")
# ++++++++++++++++++++ ATTENDANCE TOOL ++++++++++++++++++++++++++++++++++
else:
import cv2, time, os, face_recognition, streamlit as st, pyrebase, mysql.connector
from datetime import datetime, timedelta
import datetime
from PIL import Image
CreateTempDir() # Create a Temporary Directory
def clear_dir():
filelist = [f for f in os.listdir("temp") if f.endswith(".jpg")]
for f in filelist:
os.remove(os.path.join("temp", f))
clear_dir()
# --------------------------------HighLight Faces--------------------------------------------
def mark_faces(path):
if k == '1':
G = 255;
R = 0;
else:
G = 0;
R = 255
image = face_recognition.load_image_file(path) # loads the image from path
face_locations = face_recognition.face_locations(image) # finds the locations of the face
image1 = cv2.imread(path, cv2.COLOR_BGR2RGB) # Converts the color to RGB from default BGR in OpenCV
for top, right, bottom, left in face_locations:
image1 = cv2.rectangle(image, (left, top), (right, bottom), (R, G, 0), 3) # creates a rectangle on face
RGB_img = cv2.cvtColor(image1, cv2.COLOR_BGR2RGB) # Keeps the RGB image
cv2.imwrite('temp/face_highlight.jpg',
RGB_img) # Writes the RGB image with face highlighted into temp directory
disp_img = Image.open('temp/face_highlight.jpg') # Loads the image from given path
img_area.image(disp_img, width=300, caption="Current capture") # Displays the image in streamlit
# --------------------------------HighLight Faces END-----------------------------------------------
def write_file(data, filename):
with open(filename, 'wb') as file:
file.write(data)
# Code to extract image from student registration database
# ------------------------------------------------------------ Extract Photo-----------------------------------------------------------
def readBLOB(reg, filename):
print("Reading BLOB image data from registration table")
connection = mysql.connector.connect(host="sql6.freemysqlhosting.net", database="sql6409330", user="sql6409330", password="dvjW6YhuvB")
cursor = connection.cursor()
sql_fetch_blob_query = "SELECT Photo FROM registration WHERE Reg = %s"
cursor.execute(sql_fetch_blob_query, (reg,))
image = cursor.fetchone()[0]
write_file(image, filename)
cursor.close()
connection.close()
# ----------------------------------------------------------- Validate Student---------------------------------------------------------
def findstudent(reg):
connection = mysql.connector.connect(host="sql6.freemysqlhosting.net", database="sql6409330", user="sql6409330", password="dvjW6YhuvB")
cursor = connection.cursor()
sql_validate = "select NAME, EMAIL FROM registration where Reg={}".format(reg)
cursor.execute(sql_validate)
result = cursor.fetchall()
st.write("The details are")
for x in result:
st.write("Name:", x[0])
st.write("Email:", x[1])
# --------------------------------------------------------Student Regularity Check-----------------------------------------------------
# Checks whether the student was present in the previous class
def isregular(reg, subject_num):
from datetime import datetime, timedelta
d = datetime.today() - timedelta(days=1) # Finds yesterday's date
yesterday_date = str(d.strftime("%d-%m-%Y")) # Keeps yesterday's date as a formatted string
connection = mysql.connector.connect(host='localhost', database='giraffe', user='root', password='1234')
cursor = connection.cursor()
sql_find_attendance = "select `{date}` from `{subject}` where Reg={registration}".format(date=yesterday_date,
subject=subject_num,
registration=reg)
cursor.execute(sql_find_attendance)
result = cursor.fetchall()
for x in result:
return x[0] # returns '1' or '0'
# -------------------------------------------------------------------------------------------------------------------------------------
st.header("Student Companion for Attendance")
classID = st.selectbox("Select your subject", subject_config)
# min =st.number_input("Enter the duration of the meeting in MINUTES", step=1.0)
min = 1 # Setting default values of class
now = datetime.datetime.now()
start_time = now.strftime("%H:%M")
reg = st.text_input("Enter registration ID")
if st.button("Submit"):
try:
findstudent(reg)
readBLOB(reg, "temp\\me.jpg")
except:
st.error("Student isn't registered")
try:
idx = subject_config.index(classID)
classID = subject_ID[idx]
except:
st.error("Please enter valid Course ID")
k = isregular(reg, classID) # k=1 if student is present in previous class else 0
# Code to take known image from Offline System directory
# Create an encoding for the known image of the student
known_image = face_recognition.load_image_file("temp\\me.jpg")
original_encoding = face_recognition.face_encodings(known_image)[0]
capture_frequency = 10 # Intervals of frame capture in seconds
cap = cv2.VideoCapture(0) # Set webcam as video capture device
i = 1;
FaceFound = 0 # intitialise variables for counters
TotalPictures = int(min * 60 / capture_frequency) # Calculate total frames captured in a given duration
threshold = int(round(0.75 * TotalPictures)) # Keeping threshold at 75%
flag = 0
img_area = st.empty() # Placeholder for image area
while (cap.isOpened() and i <= min * 60 / capture_frequency):
ret, frame = cap.read()
if ret == False:
break
img_path = 'temp\\unknown' + str(i) + '.jpg'
cv2.imwrite(img_path, frame)
image = face_recognition.load_image_file(img_path)
face_locations = face_recognition.face_locations(image)
if not face_locations: # in case no face locations are returned i.e., []
disp_img = Image.open(img_path) # Loads the image from given path
img_area.image(disp_img, width=300,
caption="Current capture - NO FACE") # Displays the image in area of placeholder img_area
now = datetime.datetime.now()
current_time = now.strftime("%H:%M:%S")
st.write("No face detected at TIME", current_time)
else:
# Code to compare the face in captured frame with given student image
unknown_image = face_recognition.load_image_file(img_path)
unknown_encoding = face_recognition.face_encodings(unknown_image)[0]
results = face_recognition.compare_faces([original_encoding], unknown_encoding, tolerance=0.5)
if (results[0] == True): # If face is successfully recognised
mark_faces(img_path) # Calls the function which highlights the face location in Green and Red
now = datetime.datetime.now()
current_time = now.strftime("%H:%M:%S")
st.write("Student recognised at TIME ", current_time)
FaceFound += 1
else: # If face is not recognised but a face is present
disp_img = Image.open(img_path) # Loads the image from given path
img_area.image(disp_img, width=300,
caption="Current capture") # Displays the image in area of placeholder img_area
now = datetime.datetime.now()
current_time = now.strftime("%H:%M:%S")
st.write("ANOTHER PERSON found at TIME", current_time)
i += 1
time.sleep(capture_frequency) # delays the execution by 10 seconds/makes the thread sleep
flag = 1
# Displaying the results of attendance to user
st.header("Detection Metrics")
st.write("FaceRecognised", FaceFound)
st.write("Total capture", TotalPictures)
# Keep today's date in variable x
# _____________________________________
x = datetime.datetime.now()
today_date = str(x.strftime("%d-%m-%Y"))
# ______________________________________
if (FaceFound > threshold):
st.write("PRESENT")
att = 1
else:
st.write("ABSENT")
att = 0
# SQL Integration
def insertBLOB(Reg, today_date, att, subject_num):
mydb = mysql.connector.connect(host="sql6.freemysqlhosting.net", database="sql6409330", user="sql6409330", password="dvjW6YhuvB")
my_cursor = mydb.cursor()
try:
# To insert a row into the table with reg no. as primary key
sql_insert = "INSERT INTO {subject} (Reg) VALUES ({registration})".format(subject=subject_num,
registration=Reg)
print(sql_insert)
my_cursor.execute(sql_insert)
except:
print("Already present")
# To create a columm of a certain date
sql_create_column = "ALTER TABLE {subject} ADD `{day}` varchar(20)".format(subject=subject_num,
day=today_date)
# To update an existing column with the attendance
sql_insert_blob_query = "update {subject} set `{day}`={attendance} where Reg={registration}".format(
subject=subject_num, day=today_date, attendance=att, registration=Reg)
try:
my_cursor.execute(sql_create_column)
except:
print("the date column already exists")
finally:
my_cursor.execute(sql_insert_blob_query)
mydb.commit()
print("Entry updated successfully in Attendance table")
insertBLOB(reg, today_date, att, classID)
# Delete the files in temporary folder after the end of class
clear_dir()
# Close the webcam
cap.release()
cv2.destroyAllWindows()
#-----------------------------DATABASE DATA------------------------------
# Server: sql6.freemysqlhosting.net
# Name: sql6409330
# Username: sql6409330
# Password: dvjW6YhuvB
# Port number: 3306
#------------------------------------------------------------------------
#+++++++++++++++++++++++++++++++SQL QUERIES++++++++++++++++++++++++++++++
# To create a table for faculty registration
# create table facultyreg (Reg INT NOT NULL PRIMARY KEY, Name varchar(30) NOT NULL, Email varchar(30) NOT NULL, Password varchar(30) NOT NULL, Subject varchar(20));
# To create a table for student registration
# create table registration (Reg INT NOT NULL PRIMARY KEY, NAME varchar(30) NOT NULL, EMAIL varchar(30) NOT NULL,Photo LONGBLOB, password varchar(30) NOT NULL);
# To create a table for each subject
# create table subject1 (Reg INT NOT NULL PRIMARY KEY);
# create table subject2 (Reg INT NOT NULL PRIMARY KEY);
# create table subject3 (Reg INT NOT NULL PRIMARY KEY);
# create table subject4 (Reg INT NOT NULL PRIMARY KEY);
# create table subject5 (Reg INT NOT NULL PRIMARY KEY);
# INSERT INTO subject1 VALUES (0)
# INSERT INTO subject2 VALUES (0)
# INSERT INTO subject3 VALUES (0)
# INSERT INTO subject4 VALUES (0)
# INSERT INTO subject5 VALUES (0)
#++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++