diff --git a/app.yaml b/app.yaml new file mode 100644 index 0000000..a0b719d --- /dev/null +++ b/app.yaml @@ -0,0 +1 @@ +runtime: python37 diff --git a/main.py b/main.py new file mode 100644 index 0000000..4db78d3 --- /dev/null +++ b/main.py @@ -0,0 +1,38 @@ +from flask import Flask + + +# If `entrypoint` is not defined in app.yaml, App Engine will look for an app +# called `app` in `main.py`. +app = Flask(__name__) + + +@app.route('/calcAngle',methods=['get']) +def calcAngle(): + hour = int(request.args.get('hour',0)) + minute = int(request.args.get('minute',0)) + if (hour < 0 or minute < 0 or hour > 12 or minute > 60): + print('Wrong input') + if (hour == 12): + hour = 0 + if (minute == 60): + minute = 0 + + # Calculate the angles moved by + # hour and minute hands with + # reference to 12:00 + hour_angle = 0.5 * (hour * 60 + minute) + minute_angle = 6 * minute + + # Find the difference between two angles + angle = abs(hour_angle - minute_angle) + + # Return the smaller angle of two + # possible angles + angle = str(int(min(360 - angle, angle))) + + return angle +if __name__ == '__main__': + # This is used when running locally only. When deploying to Google App + # Engine, a webserver process such as Gunicorn will serve the app. This + # can be configured by adding an `entrypoint` to app.yaml. + app.run(host='127.0.0.1', port=8080, debug=True) diff --git a/main_test.py b/main_test.py new file mode 100644 index 0000000..4ce22dc --- /dev/null +++ b/main_test.py @@ -0,0 +1,12 @@ +from unittest.mock import Mock + +import main + + +def test_clock_angle(): + main.app.testing = True + client = main.app.test.test_client() + + r = client.get('/clacAngle?hour=3&minute=0') + assert r.status_code == 200 + assert '90' in r.data.decode('utf-8') diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 0000000..781d432 --- /dev/null +++ b/requirements-test.txt @@ -0,0 +1 @@ +pytest==5.3.2 diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..d318800 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +flask==1.1.2 +google-cloud-error-reporting==0.33.0