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
|
||||
|
||||
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
|
||||
|
||||
|
|
|
@ -6,6 +6,6 @@ services:
|
|||
restart: always
|
||||
mem_limit: 1024m
|
||||
ports:
|
||||
- 127.0.0.1:8050:80
|
||||
- 8050:80
|
||||
volumes:
|
||||
- ./server-web.py:/app/server.py
|
||||
|
|
|
@ -4,6 +4,8 @@ from time import sleep
|
|||
from collections import deque
|
||||
from flask import Flask as f
|
||||
from flask import Response
|
||||
from dateutil import parser
|
||||
from datetime import datetime, timedelta, timezone
|
||||
import json
|
||||
import re
|
||||
|
||||
|
@ -21,7 +23,9 @@ options.add_argument('--disable-dev-shm-usage')
|
|||
driver = webdriver.Chrome(options=options)
|
||||
q = deque()
|
||||
valuestore = {}
|
||||
datestore = {}
|
||||
app = f("web")
|
||||
h2 = timedelta(hours=2)
|
||||
|
||||
def interceptor(request, response): # A response interceptor takes two args
|
||||
if 'ws-travis.dus.com/socket.io/?EIO=3&transport=polling' in request.url :
|
||||
|
@ -38,7 +42,10 @@ def interceptor(request, response): # A response interceptor takes two args
|
|||
handleJson(j)
|
||||
else:
|
||||
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):
|
||||
if isinstance(jsonObj, list):
|
||||
|
@ -46,13 +53,14 @@ def handleJson(jsonObj):
|
|||
#typ = jsonObj[1]["LevelValues"][0]["Type"]
|
||||
value = jsonObj[1]["LevelValues"][0]["Values"]
|
||||
NmtId = jsonObj[1]["NmtId"]
|
||||
#time = jsonObj[1]["Time"]
|
||||
time = jsonObj[1]["Time"]
|
||||
valuestore[NmtId] = value
|
||||
datestore[NmtId] = time
|
||||
|
||||
# Gibt den letzten bekannten Wert fuer die NMTID zurueck
|
||||
@app.route('/nmt/<int: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]
|
||||
else:
|
||||
return "Not Found"
|
||||
|
@ -60,7 +68,7 @@ def nmtid(id):
|
|||
# Gibt eine Liste mit verfuegbaren ids zurueck
|
||||
@app.route('/ids')
|
||||
def ids():
|
||||
l = list(valuestore.keys())
|
||||
l = filter(idIsRecent,list(valuestore.keys()))
|
||||
return ','.join(map(str,l))
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
|
Loading…
Reference in a new issue