-
Notifications
You must be signed in to change notification settings - Fork 0
/
api.py
48 lines (39 loc) · 1.22 KB
/
api.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
37
38
39
40
41
42
43
44
45
46
47
48
import json
import decimal
import os
from flask import Flask, request, render_template, jsonify, current_app
USERNAME = 'you'
APP = Flask(__name__)
@APP.route('/user_info', methods=['GET', 'POST'])
def user_info():
def get_user_info():
"""
Get the axis configured values
:return: json
"""
response = jsonify({'user': USERNAME})
return response
def post_user_info():
"""
Update the axis configured values
:return: json
"""
try:
req_json = request.get_json()
new_name = req_json['user']
global USERNAME
USERNAME = new_name
response = jsonify({'status': 'success'})
return response
except:
response = jsonify({'status': 'failed', 'fail reason': 'Wrong arguments'})
return response, 500
if request.method == 'GET':
return get_user_info()
elif request.method == 'POST':
return post_user_info()
else:
response = jsonify({'status': 'failed', 'fail reason': 'Wrong method, only POST and GET available'})
return response, 401
if __name__ == '__main__':
APP.run(port='5050')