2023-10-12 14:56:30 +00:00
|
|
|
from seleniumwire import webdriver # Import from seleniumwire
|
|
|
|
from seleniumwire.utils import decode
|
|
|
|
from time import sleep
|
2023-10-15 23:08:14 +00:00
|
|
|
from collections import deque
|
2023-10-12 14:56:30 +00:00
|
|
|
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)
|
2023-10-15 23:08:14 +00:00
|
|
|
q = deque()
|
2023-10-12 14:56:30 +00:00
|
|
|
|
|
|
|
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"))
|
2023-10-15 23:08:14 +00:00
|
|
|
for i in [i for i in x if i]:
|
|
|
|
try:
|
2023-10-12 14:56:30 +00:00
|
|
|
j = json.loads(i)
|
2023-10-12 15:25:46 +00:00
|
|
|
handleJson(j)
|
2023-10-15 23:08:14 +00:00
|
|
|
except ValueError:
|
|
|
|
if i.find("online-level") > 0:
|
2023-10-15 23:34:03 +00:00
|
|
|
print ("Fixed: ", i)
|
2023-10-15 23:08:14 +00:00
|
|
|
j = json.loads(i[:i.rfind(']') + 1])
|
|
|
|
handleJson(j)
|
2023-10-15 23:34:03 +00:00
|
|
|
else:
|
|
|
|
print ("Err: ", i)
|
2023-10-15 23:08:14 +00:00
|
|
|
|
2023-10-12 15:25:46 +00:00
|
|
|
|
|
|
|
def handleJson(jsonObj):
|
|
|
|
|
2023-10-15 23:08:14 +00:00
|
|
|
if isinstance(jsonObj, list):
|
|
|
|
if 'online-level' in jsonObj:
|
|
|
|
typ = jsonObj[1]["LevelValues"][0]["Type"]
|
|
|
|
value = jsonObj[1]["LevelValues"][0]["Values"]
|
|
|
|
NmtId = jsonObj[1]["NmtId"]
|
|
|
|
time = jsonObj[1]["Time"]
|
|
|
|
|
|
|
|
q.append([typ, value, NmtId, time])
|
2023-10-12 15:25:46 +00:00
|
|
|
|
2023-10-12 14:56:30 +00:00
|
|
|
|
|
|
|
driver.response_interceptor = interceptor
|
|
|
|
|
|
|
|
driver.get('https://dus-travis.dus.com/')
|
|
|
|
|
2023-10-15 23:08:14 +00:00
|
|
|
while True:
|
|
|
|
sleep(1)
|
2023-10-15 23:34:03 +00:00
|
|
|
l = len(q)
|
|
|
|
for i in range(1, l):
|
|
|
|
a = q.pop()
|
|
|
|
#print ("[", a[3], "]: ", "NmtId: ", a[2] , " Typ: ", a[0], " Wert: ", a[1])
|
|
|
|
print("Popped ",l," Messages")
|
2023-10-12 14:56:30 +00:00
|
|
|
|