Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions app.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
entrypoint: "gunicorn -b :$PORT main:app"
runtime: python
env: flex
runtime_config:
python_version: 3
4 changes: 4 additions & 0 deletions cloudbuild.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
steps:
- name: "gcr.io/cloud-builders/gcloud"
args: ["app", "deploy"]
timeout: "1600s"
50 changes: 50 additions & 0 deletions main.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
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)

2 changes: 2 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Flask==1.1.0
gunicorn==19.6.0
19 changes: 19 additions & 0 deletions templates/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
<!DOCTYPE html>
<html>
<head>
<title>Home</title>
</head>
<body>
<h1> Calculate Angle </h1>

<form name="passdata" action="." method="POST">
<label>Enter hours:</label>
<input type="text" name="h">
<label>Enter minutes:</label>
<input type="text" name="m">
<input type="submit" name="submit" >
</form>

</div>
</body>
</html>
12 changes: 12 additions & 0 deletions templates/pass.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<!DOCTYPE html>
<html>
<head>
<title>Pass</title>
</head>
<body>
<h3>Hours: {{h}}</h3>
<h3>Minutes: {{m}}</h3>
<h3>Angle between clock hands (in Degrees): {{a}}</h3>
<h1>{{w}}</h1>
</body>
</html>