Modifying file

This commit is contained in:
chabisik 2022-12-17 22:39:15 +01:00
parent 86441e051d
commit 0fbd7be4a7

View file

@ -4,16 +4,16 @@ import threading
app = flask.Flask(import_name=__name__) app = flask.Flask(import_name=__name__)
@app.route(rule="/")
def index():
return "200 OK (working)\n"
lock = threading.Lock() lock = threading.Lock()
def opener(lck): def opener(lck):
with lck: with lck:
for _ in range(5): for _ in range(5):
requests.get("http://192.168.0.103/open") requests.get("http://192.168.0.103/open")
@app.route(rule="/")
def index():
return "200 OK (working)\n"
@app.route(rule="/receiving", methods=["POST"]) @app.route(rule="/receiving", methods=["POST"])
def receiver(): def receiver():
data = flask.request.get_data(as_text=True) data = flask.request.get_data(as_text=True)
@ -23,17 +23,35 @@ def receiver():
parameter_name, parameter_value = part.split("=") parameter_name, parameter_value = part.split("=")
data_dict[parameter_name] = parameter_value data_dict[parameter_name] = parameter_value
print(data_dict) print(data_dict)
#---action=incoming / message_type=sms--- response_events = {"events":[]}
#---action=incoming---
if data_dict["action"]=="incoming": if data_dict["action"]=="incoming":
if "please" in data_dict["message"].lower(): if "please" in data_dict["message"].lower():
op = threading.Thread(target=opener, args=(lock,)) op = threading.Thread(target=opener, args=(lock,))
op.start() op.start()
return flask.jsonify({"events":[{"event":"log","message":"Server received "+data_dict["message_type"]+" from "+data_dict["from"]}]}) response_events["events"].append({"event":"log","message":"Server received "+data_dict["message_type"]+" from "+data_dict["from"]})
#---action=incoming--- return flask.jsonify(response_events)
#---action=incoming--- #---action=outgoing---
#---action=incoming--- if data_dict["action"]=="outgoing":
#---action=incoming--- response_events["events"].append({"event":"log","message":"Server received outgoing action"})
#---action=incoming--- return flask.jsonify(response_events)
#---action=send_status---
if data_dict["action"]=="send_status":
response_events["events"].append({"event":"log","message":"Server received send_status action"})
return flask.jsonify(response_events)
#---action=forward_sent---
if data_dict["action"]=="forward_sent":
response_events["events"].append({"event":"log","message":"Server received forward_sent action"})
return flask.jsonify(response_events)
#---action=amqp_started---
if data_dict["action"]=="amqp_started":
response_events["events"].append({"event":"log","message":"Server received amqp_started action"})
return flask.jsonify(response_events)
#---action=device_status---
if data_dict["action"]=="device_status":
response_events["events"].append({"event":"log","message":"Server received notification of "+data_dict["status"]})
return flask.jsonify(response_events)
if __name__=="__main__": if __name__=="__main__":
app.run(host="0.0.0.0", debug=True) app.run(host="0.0.0.0", debug=True)