forked from mbeken/clocks
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (33 loc) · 1.2 KB
/
main.py
File metadata and controls
50 lines (33 loc) · 1.2 KB
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
from flask import Flask, request, render_template
app = Flask(__name__)
@app.route('/')
def index():
return render_template("index.html")
@app.route('/', methods=['POST'])
def calculate():
# Validating blank inputs
try:
h = float(request.form['h'])
m = float(request.form['m'])
hours = h
minutes = m
# Validation for hours and minutes values
if 0 < h <= 12 and 0 <= m < 60:
if (h == 12):
h = 0
# Calculating angles generated by movement of clock hands from 12
hour_angle = 0.5 * (h * 60 + m)
minute_angle = 6 * m
# Calculating difference between two angles of hours and minutes
angle = abs(hour_angle - minute_angle)
# Finding smaller angle
angle = min(360 - angle, angle)
return render_template("pass.html", h=hours, m=minutes, a=angle)
else:
w = "Oops.. Wrong Input !"
return render_template("pass.html", h=hours, m=minutes, w=w)
except:
w = "Sorry.. You submitted blank values !"
return render_template("pass.html", w=w)
if __name__ == '__main__':
app.run(debug=True)