-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
94 lines (74 loc) · 2.3 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
from flask import Flask, render_template, Response, request, redirect, url_for
from camera import VideoCamera
import datetime
import recognize as rcg
import pandas as pd
from speed import get_speed
app = Flask(__name__)
# reading Names in CSV
data = pd.read_csv("data.csv")
student_name = data['Name'].values
retry = 0
# first route
# >>> Redirects to Speed Check
@app.route('/')
def redirection():
print("Testing Speed")
return redirect('/speed-check')
# second route
# >>> Calls get_speed function
# >>> Checks for Bandwidth Speed
@app.route('/speed-check')
def speed():
download_sp = get_speed()
# return redirect('/form')
#if download_sp%1000000 >= 0.0 and download_sp!=-1:
if True:
print(download_sp%1000000)
return redirect('/form')
return render_template("error.html")
# third route
# >>> Renders a form for entering Name of Student
@app.route('/form')
def form():
return render_template('form.html')
# fourth route
# >>> Gets the Name from form
@app.route("/form_check", methods=['POST'])
def name():
if request.method == 'POST':
Name = request.form['Name']
try:
print(Name)
if Name in student_name:
print("Found Name in Data")
# Dump name in the Text File
with open("Names.txt", 'w') as f:
f.write(Name)
return redirect(url_for('index'))
print("Name not Found")
return redirect(url_for('form'))
# In case of any error return to the SpeedTest
except:
return redirect(url_for('redirection'))
# fifth route
# >>> Renders video Capture page
@app.route('/capture')
def index():
return render_template('index.html')
def gen(camera):
endTime = datetime.datetime.now() + datetime.timedelta(seconds=10)
while datetime.datetime.now() < endTime:
frame = camera.get_frame()
yield (b'--frame\r\n'b'Content-Type: image/jpeg\r\n\r\n' + frame + b'\r\n\r\n')
show = True
rcg.verification()
# Sixth Route
# >>> Starts Video Feed
@app.route('/video_feed')
def video_feed():
return Response(gen(VideoCamera()),
mimetype='multipart/x-mixed-replace; boundary=frame')
# Run app at Host 0.0.0.0
if __name__ == '__main__':
app.run(host='0.0.0.0', debug=True)