/
start.py
36 lines (27 loc) · 916 Bytes
/
start.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
__author__ = 'jhonjairoroa87'
import os
from flask import Flask, request
from flask.ext.jsonpify import jsonify
app = Flask(__name__)
@app.route("/")
def hello():
return "is working :)"
@app.route("/add")
def add():
try:
first_number = int(request.args.get('a'))
second_number = int(request.args.get('b'))
return jsonify({'result': first_number + second_number})
except Exception as e:
return jsonify({'result': "There was an error" + str(e)})
@app.route("/subtract")
def subtract():
try:
first_number = int(request.args.get('a'))
second_number = int(request.args.get('b'))
return jsonify({'result': first_number - second_number})
except Exception as e:
return jsonify({'result': "There was an error" + str(e)})
if __name__ == "__main__":
port = int(os.environ.get("PORT", 5000))
app.run(host='0.0.0.0', port=port)