-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
417 lines (397 loc) · 19.4 KB
/
main.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
import os
import pyttsx3
import sqlite3
import getpass
import face_recognition
import cv2
from prettytable import PrettyTable
from datetime import date
import matplotlib.pyplot as plt
import numpy as np
import attendance as atd
speak = pyttsx3.init()
conn = sqlite3.connect('attendance.db')
cursor = conn.cursor()
#cursor.execute('CREATE TABLE LOGIN_TABLE(u_id varchar(30), pass varchar(20), u_type varchar(20));')
#cursor.execute('INSERT INTO LOGIN_TABLE VALUES("admin","abcd","admin");')
#conn.commit()
speak.say("This is a system developed by Rimon, Shailesh, Vinay and Rick.")
speak.runAndWait()
login = -1
while login!=1:
speak.say("Enter your username.")
speak.runAndWait()
username = input('Enter username: ')
speak.say("Enter your password.")
speak.runAndWait()
print('Enter password: ')
password = getpass.getpass()
cursor.execute('SELECT * FROM LOGIN_TABLE WHERE u_id=?;',(username,))
for x in cursor:
global pass_valid
pass_valid = x[1]
global user_type
user_type = x[2]
if pass_valid == password:
login = 1
else:
speak.say("I'm afraid! You have entered a wrong password. Please try again.")
speak.runAndWait()
if user_type == 'admin':
speak.say("Hello Admin! Welcome to Attendance Marking System Using Face Detection. Hope you'll find it interesting.")
speak.runAndWait()
while login == 1:
speak.runAndWait()
print("""
|======================================================|
|==========Welcome To Attendance Marking System========|
|======================================================|
------------------------------------------------------
Welcome Admin!
Enter 1 : To Add New Student
Enter 2 : To Add New Faculty
Enter 3 : To View List of Faculty
Enter 4 : To View List of Students
Enter 5 : To Search Student
Enter 6 : To Search Faculty
Enter 7 : To Delete Student
Enter 8 : To Delete Faculty
Enter 9 : To Change Password
Enter 10 : To Logout
""")
speak.say("Choose one from the given option.")
speak.runAndWait()
choice = int(input('Enter your choice: '))
if choice == 1:
print('Add New Student')
s_section = input("Enter student's section: ")
s_name = input('Enter student name: ')
s_fname = input("Enter Father's name: ")
s_mname = input("Enter Mother's name: ")
s_email = input("Enter email id: ")
s_phone = input("Enter student's phone no: ")
s_pphone = input("Enter parent's phone no: ")
s_address = input("Enter address: ")
#cursor.execute("CREATE TABLE STUDENT(s_id integer PRIMARY KEY AUTOINCREMENT,s_section varchar(20), s_name varchar(30),s_fname varchar(30),s_mname varchar(30),s_email varchar(30),s_phone varchar(20),s_pphone varchar(30),s_address varchar(30));")
cursor.execute("INSERT INTO STUDENT(s_section,s_name,s_fname,s_mname,s_email,s_phone,s_pphone,s_address) VALUES(?,?,?,?,?,?,?,?);",(s_section,s_name,s_fname,s_mname,s_email,s_phone,s_pphone,s_address))
conn.commit()
print('Added to STUDENT Table')
print('Data Successfully Entered')
speak.say("Data for new student is sucessfully added.")
speak.runAndWait()
speak.say("Press any key to continue.")
speak.runAndWait()
dummy = input('Press any key to continue...........')
elif choice == 2:
print('Add New Faculty')
f_name = input('Enter Faculty name: ')
f_subject = input("Enter subject: ")
f_email = input("Enter email id: ")
f_phone = input("Enter phone no: ")
f_address = input("Enter address: ")
f_pw = 'abcd'
ac_type = 'faculty'
#cursor.execute("CREATE TABLE FACULTY_DATA(f_id integer PRIMARY KEY AUTOINCREMENT,f_name varchar(30), f_subject varchar(30),f_email varchar(30),f_phone varchar(30),f_address varchar(30),f_pass varchar(30));")
cursor.execute("INSERT INTO FACULTY_DATA(f_name,f_subject,f_email,f_phone,f_address,f_pass) VALUES(?,?,?,?,?,?);",(f_name,f_subject,f_email,f_phone,f_address,f_pw))
conn.commit()
cursor.execute("INSERT INTO LOGIN_TABLE VALUES(?,?,?);",(f_email,f_pw,ac_type));
conn.commit()
print('Data Successfully Entered')
speak.say("Data of new faculty is added sucessfully.")
speak.runAndWait()
speak.say("Press any key to continue.")
speak.runAndWait()
dummy = input('Press any key to continue...........')
elif choice == 3:
print('List of Faculties: ')
x = PrettyTable()
cursor.execute("SELECT * from FACULTY_DATA")
x.field_names = ["ID", "Name", "Subject", "Email", "Phone", "Address", "Password"]
for row in cursor:
x.add_row([row[0],row[1],row[2],row[3],row[4],row[5],row[6]]);
print(x)
speak.say("Press any key to continue.")
speak.runAndWait()
dummy = input('Press any key to continue...........')
elif choice == 4:
print('List of Students: ')
x = PrettyTable()
cursor.execute("SELECT * from STUDENT")
x.field_names = ["ID", "Section", "Name", "Father's Name", "Mother's Name", "Email", "Phone No", "Parent's Phone", "Address"]
for row in cursor:
x.add_row([row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8]]);
print(x)
speak.say("Press any key to continue.")
speak.runAndWait()
dummy = input('Press any key to continue...........')
elif choice == 5:
print("Search Student")
print("1)Search by ID")
print("2)Search by Name:")
choice = int(input('Enter 1 or 2......'))
if choice == 1:
key = input('Enter ID: ')
speak.say("please enter you identification.")
speak.runAndWait()
x = PrettyTable()
cursor.execute("SELECT * from STUDENT_DATA WHERE s_id = ?;", key)
x.field_names = ["ID", "Section", "Name", "Father's Name", "Mother's Name", "Email", "Phone No", "Parent's Phone", "Address"]
for row in cursor:
x.add_row([row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8]]);
print(x)
dummy = input('Press any key to continue...........')
speak.say("Press any key to continue.")
speak.runAndWait()
if choice == 2:
key = input('Enter Name: ')
key = key+'%'
x = PrettyTable()
cursor.execute("SELECT * from STUDENT_DATA WHERE s_name LIKE ?;", (key,))
x.field_names = ["ID", "Section", "Name", "Father's Name", "Mother's Name", "Email", "Phone No", "Parent's Phone", "Address"]
for row in cursor:
x.add_row([row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8]]);
print(x)
speak.say("Press any key to continue.")
speak.runAndWait()
dummy = input('Press any key to continue...........')
elif choice == 6:
print("Search Faculty")
key = input('Enter Name: ')
x = PrettyTable()
cursor.execute("SELECT * from FACULTY_DATA where f_name LIKE ?;", key)
x.field_names = ["ID", "Name", "Subject", "Email", "Phone", "Address", "Password"]
for row in cursor:
x.add_row([row[0],row[1],row[2],row[3],row[4],row[5],row[6]]);
print(x)
dummy = input('Press any key to continue...........')
speak.say("Press any key to continue.")
speak.runAndWait()
elif choice == 7:
print('Delete Student: ')
key = input('Enter ID: ')
cursor.execute("DELETE from STUDENT WHERE s_id = ?;", (key,))
conn.commit()
print('Success')
speak.say("Student data is successfully deleted.")
speak.runAndWait()
speak.say("Press any key to continue.")
speak.runAndWait()
dummy = input('Press any key to continue...........')
elif choice == 8:
print('Delete Faculty: ')
key = input('Enter email ID: ')
cursor.execute("DELETE from FACULTY_DATA WHERE f_email = ?;", (key,))
print('Deleted from FACULTY_DATA')
conn.commit()
cursor.execute("DELETE from LOGIN_TABLE WHERE u_id = ?;", (key,))
print('Deleted from LOGIN_TABLE')
conn.commit()
speak.say("Faculty data is successfully deleted.")
speak.runAndWait()
speak.say("Press any key to continuue.")
speak.runAndWait()
dummy = input('Press any key to continue...........')
elif choice == 9:
success = -1
while success!=1:
print('Enter password: ')
speak.say("Give password or leave.")
speak.runAndWait()
password = getpass.getpass()
cursor.execute('SELECT * FROM LOGIN_TABLE WHERE u_id=?;',(username,))
for x in cursor:
pass_val = x[1]
if pass_val == password:
newp = input('Please enter new password: ')
speak.say("Please enter new password.")
speak.runAndWait()
cursor.execute("UPDATE LOGIN_TABLE set pass=? where u_id=?;",(newp,username))
conn.commit()
success = 1
print('Password Changed')
speak.say("Password changed successfully.")
speak.runAndWait()
login = 0
else:
print("I'm afraid! You have entered a wrong password. Please try again.")
speak.say("I'm afraid! You have entered a wrong password. Please try again.")
speak.runAndWait()
elif choice == 10:
login = 0
speak.say("You are successfully logged out.")
speak.runAndWait()
print('You are successfully logged out')
elif user_type == 'faculty':
speak.say("Hello Faculty! Welcome to Attendance Marking System Using Face Detection. Hope you'll find it interesting.")
speak.runAndWait()
while login == 1:
cursor.execute("SELECT * from FACULTY_DATA where f_email=?;",(username,))
for row in cursor:
fac_name = row[1]
print("""
|======================================================|
|==========Welcome To Attendance Marking System========|
|======================================================|
------------------------------------------------------
Welcome Faculty!
Enter 1 : To View List of Students
Enter 2 : To Search Student
Enter 3 : To Mark Attendance
Enter 4 : To View Attendance
Enter 5 : To Visualize Attendance
Enter 6 : To Change Password
Enter 7 : To Logout
""")
speak.say("Choose from following options .")
speak.runAndWait()
choice = int(input('Enter your choice: '))
if choice == 1:
section = input('Enter the section: ')
print('List of Students: ')
x = PrettyTable()
cursor.execute("SELECT * from STUDENT where s_section = ?",(section,))
x.field_names = ["ID", "Section", "Name", "Father's Name", "Mother's Name", "Email", "Phone No", "Parent's Phone", "Address"]
for row in cursor:
x.add_row([row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8]]);
print(x)
speak.say("Press any key to continue.")
speak.runAndWait()
dummy = input('Press any key to continue...........')
elif choice == 2:
print("Search Student")
print("1)Search by ID")
print("2)Search by Name:")
choice = int(input('Enter 1 or 2......'))
if choice == 1:
key = input('Enter ID: ')
speak.say("Enter identification.")
speak.runAndWait()
x = PrettyTable()
cursor.execute("SELECT * from STUDENT WHERE s_id = ?;", key)
x.field_names = ["ID", "Section", "Name", "Father's Name", "Mother's Name", "Email", "Phone No", "Parent's Phone", "Address"]
for row in cursor:
x.add_row([row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8]]);
print(x)
dummy = input('Press any key to continue...........')
speak.say("Press any key to continue.")
speak.runAndWait()
if choice == 2:
key = input('Enter Name: ')
key = key+'%'
x = PrettyTable()
cursor.execute("SELECT * from STUDENT WHERE s_name LIKE ?;", (key,))
x.field_names = ["ID", "Section", "Name", "Father's Name", "Mother's Name", "Email", "Phone No", "Parent's Phone", "Address"]
for row in cursor:
x.add_row([row[0],row[1],row[2],row[3],row[4],row[5],row[6],row[7],row[8]]);
print(x)
speak.say("Press any key to continue.")
speak.runAndWait()
dummy = input('Press any key to continue...........')
elif choice == 3:
section = input('Enter Section: ')
today = input('Enter date in DD-MM-YYYY format: ')
slot = input('Enter time slot: ')
fac_subject = input('Enter subject')
atd.attend()
s_present = atd.names
print('Name of present Students: ',s_present)
#cursor.execute("CREATE TABLE attendance(section varchar(10),s_name varchar(20),date varchar(20), time varchar(20), subject varchar(20), marked_by varchar(40), remark varchar(20));")
cursor.execute("SELECT * from STUDENT where s_section=?;",(section,))
s_all = []
for row in cursor:
s_all.append(row[2])
print('Name of all students: ', s_all)
for i in range(len(s_all)):
if s_all[i] in s_present:
rem = 'Present'
cursor.execute("INSERT INTO attendance VALUES(?,?,?,?,?,?,?);",(section,s_all[i],today,slot,fac_subject,fac_name,rem))
conn.commit()
else:
rem = 'Absent'
cursor.execute("INSERT INTO attendance VALUES(?,?,?,?,?,?,?);",(section,s_all[i],today,slot,fac_subject,fac_name,rem))
conn.commit()
dummy = input('Press any key to continue...........')
elif choice == 4:
cursor.execute("SELECT * FROM attendance;")
x = PrettyTable()
x.field_names = ["Section", "Student Name", "Date", "Time", "Subject", "Marked by", "Remark"]
for row in cursor:
x.add_row([row[0],row[1],row[2],row[3],row[4],row[5],row[6]]);
print(x)
speak.say("Press any key to continue.")
speak.runAndWait()
dummy = input('Press any key to continue...........')
elif choice == 5:
print('Visualize Attendance')
print('1)Attendance of a particular student.')
print('2)Attendance of a particular section.')
choice = int(input('Enter your choice..'))
if choice == 1:
print('Enter details:')
countp = 0
total = 0
vis_student_name = input('Enter student name: ')
vis_student_sec = input('Enter student section: ')
cursor.execute("SELECT * FROM attendance where s_name = ? AND section = ?;",(vis_student_name,vis_student_sec))
for row in cursor:
if row[6] == 'Present':
countp += 1
total +=1
absent = total - countp
att_perc = (countp/total)*100
print('Attendance percentage : ' + str(att_perc))
labels = ['Present','Absent']
vals = [countp,absent]
colors = ['green','red']
patches, texts = plt.pie(vals, colors=colors, shadow=True, startangle=90)
plt.legend(patches, labels, loc="best")
plt.axis('equal')
plt.tight_layout()
plt.show()
speak.say("Press any key to continue.")
speak.runAndWait()
dummy = input('Press any key to continue...........')
elif choice == 2:
countp = 0
total = 0
print('Enter details:')
vis_student_sec = input('Enter section: ')
cursor.execute("SELECT * FROM attendance where section = ?;",(vis_student_sec,))
for row in cursor:
if row[6] == 'Present':
countp += 1
total +=1
absent = total - countp
att_perc = (countp/total)*100
print('Attendance percentage : ' + str(att_perc))
labels = ['Present','Absent']
vals = [countp,absent]
colors = ['green','red']
patches, texts = plt.pie(vals, colors=colors, shadow=True, startangle=90)
plt.legend(patches, labels, loc="best")
plt.axis('equal')
plt.tight_layout()
plt.show()
speak.say("Press any key to continue.")
speak.runAndWait()
elif choice == 6:
success = -1
while success!=1:
print('Enter password: ')
password = getpass.getpass()
cursor.execute('SELECT * FROM LOGIN_TABLE WHERE u_id=?;',(username,))
for x in cursor:
pass_val = x[1]
if pass_val == password:
newp = input('Please enter new password: ')
cursor.execute("UPDATE LOGIN_TABLE set pass=? where u_id=?;",(newp,username))
conn.commit()
cursor.execute("UPDATE FACULTY_DATA set f_pass=? where f_email=?;",(newp,username))
conn.commit()
success = 1
login = 0
else:
print("I'm afraid! You have entered a wrong password. Please try again.")
elif choice == 7:
login = 0
print('You are successfully logged out')