diff --git a/app.yaml b/app.yaml new file mode 100644 index 0000000..8a45112 --- /dev/null +++ b/app.yaml @@ -0,0 +1,5 @@ +entrypoint: "gunicorn -b :$PORT main:app" +runtime: python +env: flex +runtime_config: + python_version: 3 diff --git a/cloudbuild.yaml b/cloudbuild.yaml new file mode 100644 index 0000000..e4a1483 --- /dev/null +++ b/cloudbuild.yaml @@ -0,0 +1,4 @@ +steps: +- name: "gcr.io/cloud-builders/gcloud" + args: ["app", "deploy"] +timeout: "1600s" diff --git a/main.py b/main.py new file mode 100644 index 0000000..ca502a0 --- /dev/null +++ b/main.py @@ -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) + diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..bf04841 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +Flask==1.1.0 +gunicorn==19.6.0 diff --git a/templates/index.html b/templates/index.html new file mode 100644 index 0000000..8c45656 --- /dev/null +++ b/templates/index.html @@ -0,0 +1,19 @@ + + + + Home + + +

Calculate Angle

+ +
+ + + + + +
+ + + + diff --git a/templates/pass.html b/templates/pass.html new file mode 100644 index 0000000..81dc9bb --- /dev/null +++ b/templates/pass.html @@ -0,0 +1,12 @@ + + + + Pass + + +

Hours: {{h}}

+

Minutes: {{m}}

+

Angle between clock hands (in Degrees): {{a}}

+

{{w}}

+ +