recency check. at night times not all stations print recent results
This commit is contained in:
parent
32dfb91a0a
commit
ae7335c3df
|
@ -1,7 +1,7 @@
|
||||||
FROM python:3.10
|
FROM python:3.10
|
||||||
|
|
||||||
RUN pip install --no-cache-dir --upgrade pip && \
|
RUN pip install --no-cache-dir --upgrade pip && \
|
||||||
pip install --no-cache-dir selenium-wire flask
|
pip install --no-cache-dir selenium-wire flask python-dateutil
|
||||||
|
|
||||||
RUN apt-get update && apt-get -y install chromium
|
RUN apt-get update && apt-get -y install chromium
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,6 @@ services:
|
||||||
restart: always
|
restart: always
|
||||||
mem_limit: 1024m
|
mem_limit: 1024m
|
||||||
ports:
|
ports:
|
||||||
- 127.0.0.1:8050:80
|
- 8050:80
|
||||||
volumes:
|
volumes:
|
||||||
- ./server-web.py:/app/server.py
|
- ./server-web.py:/app/server.py
|
||||||
|
|
|
@ -4,6 +4,8 @@ from time import sleep
|
||||||
from collections import deque
|
from collections import deque
|
||||||
from flask import Flask as f
|
from flask import Flask as f
|
||||||
from flask import Response
|
from flask import Response
|
||||||
|
from dateutil import parser
|
||||||
|
from datetime import datetime, timedelta, timezone
|
||||||
import json
|
import json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
@ -21,7 +23,9 @@ options.add_argument('--disable-dev-shm-usage')
|
||||||
driver = webdriver.Chrome(options=options)
|
driver = webdriver.Chrome(options=options)
|
||||||
q = deque()
|
q = deque()
|
||||||
valuestore = {}
|
valuestore = {}
|
||||||
|
datestore = {}
|
||||||
app = f("web")
|
app = f("web")
|
||||||
|
h2 = timedelta(hours=2)
|
||||||
|
|
||||||
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 :
|
||||||
|
@ -40,19 +44,23 @@ def interceptor(request, response): # A response interceptor takes two args
|
||||||
print ("Err: ", i)
|
print ("Err: ", i)
|
||||||
|
|
||||||
|
|
||||||
|
def idIsRecent(id):
|
||||||
|
return id in valuestore and datetime.now(timezone.utc) - parser.parse(datestore[id]) < timedelta(seconds=30)
|
||||||
|
|
||||||
def handleJson(jsonObj):
|
def handleJson(jsonObj):
|
||||||
if isinstance(jsonObj, list):
|
if isinstance(jsonObj, list):
|
||||||
if 'online-level' in jsonObj:
|
if 'online-level' in jsonObj:
|
||||||
#typ = jsonObj[1]["LevelValues"][0]["Type"]
|
#typ = jsonObj[1]["LevelValues"][0]["Type"]
|
||||||
value = jsonObj[1]["LevelValues"][0]["Values"]
|
value = jsonObj[1]["LevelValues"][0]["Values"]
|
||||||
NmtId = jsonObj[1]["NmtId"]
|
NmtId = jsonObj[1]["NmtId"]
|
||||||
#time = jsonObj[1]["Time"]
|
time = jsonObj[1]["Time"]
|
||||||
valuestore[NmtId] = value
|
valuestore[NmtId] = value
|
||||||
|
datestore[NmtId] = time
|
||||||
|
|
||||||
# Gibt den letzten bekannten Wert fuer die NMTID zurueck
|
# Gibt den letzten bekannten Wert fuer die NMTID zurueck
|
||||||
@app.route('/nmt/<int:id>')
|
@app.route('/nmt/<int:id>')
|
||||||
def nmtid(id):
|
def nmtid(id):
|
||||||
if id in valuestore:
|
if id in valuestore and datetime.now(timezone.utc) - parser.parse(datestore[id]) < timedelta(seconds=30):
|
||||||
return valuestore[id]
|
return valuestore[id]
|
||||||
else:
|
else:
|
||||||
return "Not Found"
|
return "Not Found"
|
||||||
|
@ -60,7 +68,7 @@ def nmtid(id):
|
||||||
# Gibt eine Liste mit verfuegbaren ids zurueck
|
# Gibt eine Liste mit verfuegbaren ids zurueck
|
||||||
@app.route('/ids')
|
@app.route('/ids')
|
||||||
def ids():
|
def ids():
|
||||||
l = list(valuestore.keys())
|
l = filter(idIsRecent,list(valuestore.keys()))
|
||||||
return ','.join(map(str,l))
|
return ','.join(map(str,l))
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
|
Loading…
Reference in a new issue