-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhas_api.py
27 lines (24 loc) · 871 Bytes
/
has_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
import flask
import flask_restful
from flask_cors import CORS
import os
if __name__ == "__main__":
app = flask.Flask(__name__)
api = flask_restful.Api(app)
CORS(app)
class RunHAS(flask_restful.Resource):
def post(self):
data = flask.request.get_json()
if data:
config_path = data.get("config")
if config_path:
status = os.system("python /home/has/src/has_controller.py --config {}".format(config_path))
if status:
return 500, "Errors while running this command."
return 200, "Done Successfully"
else:
return 400, "No config Specified."
else:
return 400, "No Data."
api.add_resource(RunHAS, "/run")
app.run(host=host, port=7000)