catches all errors known to date

This commit is contained in:
Bla 2023-10-15 23:08:14 +00:00
parent b6ff3c3ca6
commit c2aa4c0a9e

View file

@ -1,6 +1,7 @@
from seleniumwire import webdriver # Import from seleniumwire from seleniumwire import webdriver # Import from seleniumwire
from seleniumwire.utils import decode from seleniumwire.utils import decode
from time import sleep from time import sleep
from collections import deque
import json import json
import re import re
@ -16,37 +17,43 @@ options.add_argument('--disable-dev-shm-usage')
# Create a new instance of the Chrome driver # Create a new instance of the Chrome driver
driver = webdriver.Chrome(options=options) driver = webdriver.Chrome(options=options)
q = deque()
def interceptor(request, response): # A response interceptor takes two args def interceptor(request, response): # A response interceptor takes two args
if 'ws-travis.dus.com/socket.io/?EIO=3&transport=polling' 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')) body = decode(response.body, response.headers.get('Content-Encoding', 'identity'))
x = re.split("\d\d\d:\d\d\/dus,", body.decode("utf-8")) 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]:
for i in [i for i in x if i]: try:
j = json.loads(i) j = json.loads(i)
handleJson(j) handleJson(j)
else: except ValueError:
j = json.loads(x) print ("\nErr: ", i, "\n")
handleJson(j) if i.find("online-level") > 0:
j = json.loads(i[:i.rfind(']') + 1])
handleJson(j)
def handleJson(jsonObj): def handleJson(jsonObj):
if 'online-level' in jsonObj: if isinstance(jsonObj, list):
typ = jsonObj[1]["LevelValues"][0]["Type"] if 'online-level' in jsonObj:
values = jsonObj[1]["LevelValues"][0]["Values"] typ = jsonObj[1]["LevelValues"][0]["Type"]
NmtId = jsonObj[1]["NmtId"] value = jsonObj[1]["LevelValues"][0]["Values"]
time = jsonObj[1]["Time"] NmtId = jsonObj[1]["NmtId"]
time = jsonObj[1]["Time"]
print ("\n", jsonObj)
print ("[", time, "]: ", "NmtId: ", NmtId, " Typ: ", typ, " Wert: ", values) q.append([typ, value, NmtId, time])
print ("\n")
driver.response_interceptor = interceptor driver.response_interceptor = interceptor
# Go to the Google home page
driver.get('https://dus-travis.dus.com/') driver.get('https://dus-travis.dus.com/')
sleep(1000) while True:
sleep(1)
for i in range(1, len(q)):
a = q.popleft()
print ("[", a[3], "]: ", "NmtId: ", a[2] , " Typ: ", a[0], " Wert: ", a[1])