1
0
Fork 0
Browse Source

add try-blocks to post requests.

stable
Craig Oates 4 years ago
parent
commit
b01178a711
  1. 2
      app/app.py
  2. 58
      app/services/post_services.py

2
app/app.py

@ -21,4 +21,4 @@ def robots():
return render_template("robots.txt")
if __name__ == "__main__":
app.run(host="0.0.0.0", debug=True)
app.run(host="0.0.0.0", debug=False)

58
app/services/post_services.py

@ -19,34 +19,40 @@ the same directory as this: /services/.
device_check_token = "QWERTYuiopasdfghjklzxcvbnm_1234567890"
def add_latest_reading(meter, info):
if info["token"] == device_check_token:
reading = {"reading":info["reading"], "time":info["time"]}
if meter == 1:
return add_reading_to_meter1(reading)
elif meter == 2:
return add_reading_to_meter2(reading)
elif meter == 3:
return add_reading_to_meter3(reading)
return make_response("Meter Id. not recognised. Must be between 1 and 3.", 400)
return make_response("Invalid token.", 400)
try:
if info["token"] == device_check_token:
reading = {"reading":info["reading"], "time":info["time"]}
if meter == 1:
return add_reading_to_meter1(reading)
elif meter == 2:
return add_reading_to_meter2(reading)
elif meter == 3:
return add_reading_to_meter3(reading)
return make_response("Meter Id. not recognised. Must be between 1 and 3.", 400)
return make_response("Invalid token.", 400)
except:
return make_response("The data you sent was invalid or incorrectly formatted.", 400)
def log_status_change(device, info):
if info["token"] == device_check_token:
status = {"time":info["time"], "status":info["status"]}
if device == 1:
return add_status_change_to_device1(status)
elif device == 2:
return add_status_change_to_device2(status)
elif device == 3:
return add_status_change_to_device3(status)
elif device == 4:
return add_status_change_to_device4(status)
elif device == 5:
return add_status_change_to_device5(status)
elif device == 6:
return add_status_change_to_device6(status)
return make_response("Device Id. not recognised. Must be between 1 and 6.", 400)
return make_response("Invalid token.", 400)
try:
if info["token"] == device_check_token:
status = {"time":info["time"], "status":info["status"]}
if device == 1:
return add_status_change_to_device1(status)
elif device == 2:
return add_status_change_to_device2(status)
elif device == 3:
return add_status_change_to_device3(status)
elif device == 4:
return add_status_change_to_device4(status)
elif device == 5:
return add_status_change_to_device5(status)
elif device == 6:
return add_status_change_to_device6(status)
return make_response("Device Id. not recognised. Must be between 1 and 6.", 400)
return make_response("Invalid token.", 400)
except:
return make_response("The data you sent was invalid or incorrectly formatted.", 400)
'''
Nitty-Gritty Functions