-
Notifications
You must be signed in to change notification settings - Fork 0
/
project.py
executable file
·138 lines (122 loc) · 3.63 KB
/
project.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
from flask import Flask
import hashlib
import json
import boto3
from flaskext.mysql import MySQL
app = Flask(__name__)
mysql = MySQL()
# MySQL configurations
app.config['MYSQL_DATABASE_USER'] = 'master'
app.config['MYSQL_DATABASE_PASSWORD'] = 'qwerty123'
app.config['MYSQL_DATABASE_DB'] = 'attendance'
app.config['MYSQL_DATABASE_HOST'] = 'project.cubis4lnt2kc.ap-south-1.rds.amazonaws.com'
mysql.init_app(app)
@app.route('/')
def hello_world():
return 'Hello World!'
@app.route("/process/<image_name>")
def process(image_name) :
d=image_name.split("_")
client = boto3.client('rekognition',aws_access_key_id="AKIAIVCDOBME6US2GYTQ",aws_secret_access_key="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",region_name="ap-south-1")
con=mysql.connect()
cur=con.cursor()
cur.execute("select usn,faceid from stu_auth where usn in (select usn from "+d[0]+")")
res=cur.fetchall()
cur.close()
con.close()
present=[]
absent=[]
response = client.index_faces(
CollectionId=d[0],
Image={
'S3Object': {
'Bucket': 'attendaceupload',
'Name': image_name,
}
},
ExternalImageId=image_name,
DetectionAttributes=[
'DEFAULT',
],
MaxFaces=80,
QualityFilter='NONE'
)
temp_image_ids=[]
for i in response["FaceRecords"]:
temp_image_ids.append(i["Face"]["FaceId"])
try:
for face in res:
if(client.search_faces(CollectionId=d[0],FaceId=face[1],MaxFaces=1)["FaceMatches"]):
present.append(face[0])
else:
absent.append(face[0])
finally:
response=client.delete_faces(CollectionId=d[0],FaceIds=temp_image_ids)
intruder=len(temp_image_ids)-len(present)
return json.dumps({"present":present,"absent":absent, "intruder":intruder})
@app.route('/update/<courseid>/<present>')
def update(courseid,present):
con=mysql.connect()
cur=con.cursor()
cur.execute("update "+courseid+" set count=count+1 where usn in ("+present[1:-1:]+")")
cur.execute('update courses set count=count+1 where cid="'+courseid+'"')
cur.execute('commit;')
cur.close()
con.close()
return 'OK'
@app.route('/teacher-login/<id>/<password>/')
def tlogin(id,password):
con = mysql.connect()
id=id.upper()
cur = con.cursor()
cur.execute("select password from lec_details where id='"+id+"'");
result=cur.fetchall()
cur.close()
con.close()
# password= hashlib.md5(password).hexdigest()
if result==None:
return "user-not-found"
if(result[0][0]==password):
return "OK"
else:
return "wrong-password"
@app.route('/teacher-courses/<tid>/')
def tcourses(tid):
con=mysql.connect()
cur=con.cursor()
cur.execute("select cid,cname from courses where tid='"+tid+"'")
result = cur.fetchall()
cur.close()
con.close()
final={}
j=1
for row in result:
fdata = {}
fdata['cid']=row[0]
fdata['cname']=row[1]
final["id"+str(j)]=fdata
j+=1
new = {'len': len(final), 'data': final}
final = json.dumps(new)
return final
# @app.route('/courses/')
# def courses():
# con = mysql.connect()
# cur = con.cursor()
# cur.execute("select cid,cname from courses")
# result =cur.fetchall()
# cur.close()
# con.close()
# final = {}
# i=1
# for row in result:
# fdata = {}
# fdata['cid'] = row[0]
# fdata['cname'] = row[1]
# final['id'+str(i)]=fdata
# i+=1
# new={'len':len(final),'data':final}
# final = json.dumps(new)
# return final
if __name__ == '__main__':
app.run(debug=True,host='0.0.0.0',port=8080)