-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
65 lines (48 loc) · 1.75 KB
/
Copy pathmain.py
File metadata and controls
65 lines (48 loc) · 1.75 KB
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
import os
import sys
from flask import jsonify
from Core import validate, parse, find_location
def main(request, test=False):
try:
# to be able to test the function locally , added the test parameter
data = request if test else request.get_json()
result = validate(data)
if result is "payload":
data = parse(data=data)
print(data)
data = find_location(data=data)
from configuration import data_root
data_root.document(data["time"]).set(data)
print(data)
return jsonify(data), 200
elif result is "Config":
for station, cord in data["Config"].items():
from configuration import Config_root
Config_root.document(station).set(cord)
data["Status"] = "Config Writen Successfully "
return jsonify(data), 200
else:
validate("")
except Exception as e:
if test:
exc_type, exc_obj, exc_tb = sys.exc_info()
fname = os.path.split(exc_tb.tb_frame.f_code.co_filename)[1]
print(exc_type, fname, exc_tb.tb_lineno, sys.exc_info())
return (
jsonify(
{
"Error": "Unexpected Error Occurred While processing the Message",
"Details": str(e),
}
),
500,
)
if __name__ == "__main__":
request = {"time": "1576077223", "device": "336B67", "data": "3f0002d50003c50001c32402"}
try:
ENV = os.getenv("ENV", "dev")
test = True if ENV == "dev" or ENV == "test" else False
main(request, test=test)
except RuntimeError:
# Flask Context Error , Passed for testing
pass