-
Notifications
You must be signed in to change notification settings - Fork 0
/
remove_student.py
62 lines (52 loc) · 1.82 KB
/
remove_student.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
import os
import pickle
def load_encoded_file():
global en_no
en_no = input("Enter the en_no to remove: ")
global encoded_img
global en_no_list
with open('./FaceSnap-Attendance-System/database/enc_img_eno_list.p','rb') as file:
encoded_img,en_no_list = pickle.load(file=file)
def remove_enno(en_no_list):
global target_index
if en_no in en_no_list:
target_index = en_no_list.index(en_no)
en_no_list.pop(target_index)
print(f"{en_no} removed Succesfully")
else:
print("Number not present")
def remove_encoded_image(encoded_image_list):
encoded_image_list.pop(target_index)
print("Image encodings removed")
def remove_image(en):
path = "./FaceSnap-Attendance-System/database/assets"
images = os.listdir(path=path)
# print(images)
# print(os.path.splitext(images[0]))
for image in images:
if en in os.path.splitext(image):
image_path = os.path.join(path,image)
os.remove(image_path)
print("Image removed")
def create_encode_file():
encoded_img_eno_list = [encoded_img,en_no_list]
with open('./FaceSnap-Attendance-System/database/enc_img_eno_list.p','wb') as file:
pickle.dump(encoded_img_eno_list,file=file)
print('file saved')
def delete_student():
load_encoded_file()
# Remove en_no from list
if en_no in en_no_list:
remove_enno(en_no_list) # Enno list
# Remove Image from data base
remove_encoded_image(encoded_img) # encoded image list
# Remove_image(en_no)
remove_image(en_no)
# Updating the list
create_encode_file()
else:
print("Student not found. Plesae add the student first")
if __name__=="__main__":
delete_student()
# print(encoded_img)
# print(en_no_list)