dus-flughafen-foo/server.py

53 lines
1.6 KiB
Python
Raw Normal View History

2023-10-12 14:56:30 +00:00
from seleniumwire import webdriver # Import from seleniumwire
from seleniumwire.utils import decode
from time import sleep
import json
import re
options = webdriver.ChromeOptions()
options.add_argument('--headless')
options.add_argument("--incognito")
options.add_argument("--nogpu")
options.add_argument("--disable-gpu")
options.add_argument("--window-size=1280,1280")
options.add_argument("--no-sandbox")
options.add_argument("--enable-javascript")
options.add_argument('--disable-dev-shm-usage')
# Create a new instance of the Chrome driver
driver = webdriver.Chrome(options=options)
def interceptor(request, response): # A response interceptor takes two args
2023-10-12 15:25:46 +00:00
if 'ws-travis.dus.com/socket.io/?EIO=3&transport=polling' in request.url :
2023-10-12 14:56:30 +00:00
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)
2023-10-12 15:25:46 +00:00
handleJson(j)
2023-10-12 14:56:30 +00:00
else:
j = json.loads(x)
2023-10-12 15:25:46 +00:00
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")
2023-10-12 14:56:30 +00:00
driver.response_interceptor = interceptor
# Go to the Google home page
driver.get('https://dus-travis.dus.com/')
sleep(1000)