From d86371263061c0418c0f86ea5e5794f8ae6b4f03 Mon Sep 17 00:00:00 2001 From: Bla Date: Thu, 12 Oct 2023 15:25:46 +0000 Subject: [PATCH] example processing --- README.md | 7 +++++++ server.py | 23 ++++++++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..5b967b6 --- /dev/null +++ b/README.md @@ -0,0 +1,7 @@ +# Flughafen Sensor foo + +Das Projekt wird gestartet mit `docker compose up` (`docker-compose up`) + +Bisher werden nur daten des Typs "online-level" verarbeitet, aber der Rest sollte einigermassen trivial sein. + +Ich habe keine Ahnung, wie und in welchem Format ihr das an euren zentralen Thinger Server senden wollt, aber kÃnnt ihr vieleicht auch selber erledigen. diff --git a/server.py b/server.py index 81faf0c..25cf45d 100644 --- a/server.py +++ b/server.py @@ -19,20 +19,29 @@ driver = webdriver.Chrome(options=options) def interceptor(request, response): # A response interceptor takes two args - if 'ws-travis.dus.com/socket.io/' in request.url : + if 'ws-travis.dus.com/socket.io/?EIO=3&transport=polling' in request.url : body = decode(response.body, response.headers.get('Content-Encoding', 'identity')) x = re.split("\d\d\d:\d\d\/dus,", body.decode("utf-8")) if len(x) > 1: for i in [i for i in x if i]: j = json.loads(i) - print (j) + handleJson(j) else: j = json.loads(x) - print (j) - #offset = str(body).find('[') - #print ("\n" , str(body)[offset:] , "\n") - #j = json.loads(body[offset:]) - #print (x) + handleJson(j) + +def handleJson(jsonObj): + + if jsonObj[0] == 'online-level': + typ = jsonObj[1]["LevelValues"][0]["Type"] + values = jsonObj[1]["LevelValues"][0]["Values"] + NmtId = jsonObj[1]["NmtId"] + time = jsonObj[1]["Time"] + + print ("\n", jsonObj) + print ("[", time, "]: ", "NmtId: ", NmtId, " Typ: ", typ, " Wert: ", values) + print ("\n") + driver.response_interceptor = interceptor