-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
35 lines (26 loc) · 908 Bytes
/
main.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
from flask import Flask, json, request
app = Flask(__name__)
'''
@app.route("/", methods=['GET')
def home():
return render_template("home.html")
'''
@app.route('/', methods=['GET', 'DELETE', 'POST', 'PUT'])
def index():
res = {}
try:
if request.method == 'PUT' or request.method == 'POST':
json_data = json.loads(request.data)
for k, v in json_data.items():
data = k
values = list([int(x) for x in v.split(',')])
values.sort()
values = ','.join(map(str, values))
res[data] = values
else:
res["error"] = "Please use PUT or POST for your requests..."
except:
res["error"] = "Please use the following json format for your requests: {'data': '0,1,2'}"
return json.dumps(res)
if __name__ == "__main__":
app.run(debug=True, host='0.0.0.0')