aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2022-10-31 21:24:00 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2022-10-31 21:24:00 +0100
commitf2e50faab6a3447c061500cd1a735424af055669 (patch)
treecfa806529eb74ef1ba1a0fa086499c4bc34510ce
parent8fd1aa2422a55e187f1c1c82c68daaf833d63865 (diff)
downloadglutte-serial-web-f2e50faab6a3447c061500cd1a735424af055669.tar.gz
glutte-serial-web-f2e50faab6a3447c061500cd1a735424af055669.tar.bz2
glutte-serial-web-f2e50faab6a3447c061500cd1a735424af055669.zip
Go back to using time()
-rwxr-xr-xglutte_serial_web.py8
-rw-r--r--serialrx.py6
2 files changed, 10 insertions, 4 deletions
diff --git a/glutte_serial_web.py b/glutte_serial_web.py
index 2c53094..5ca905c 100755
--- a/glutte_serial_web.py
+++ b/glutte_serial_web.py
@@ -23,6 +23,7 @@
# SOFTWARE.
import time
+import datetime
import json
from geventwebsocket.handler import WebSocketHandler
from gevent import pywsgi, Timeout
@@ -48,7 +49,12 @@ def history():
if config.CACHE_FILE:
with open(config.CACHE_FILE) as fd:
hist = json.load(fd)
- text = "\n".join(f"{entry['ts'].isoformat()} {entry['line']}" for entry in hist)
+
+ def format_entry(entry):
+ dt = datetime.datetime.fromtimestamp(entry['ts']).isoformat()
+ return f"{dt} {entry['line']}"
+
+ text = "\n".join(format_entry(entry) for entry in hist)
return Response(text, mimetype='text/plain')
@app.route('/stats')
diff --git a/serialrx.py b/serialrx.py
index f6007ea..f3fc9af 100644
--- a/serialrx.py
+++ b/serialrx.py
@@ -140,16 +140,16 @@ class SerialRX(threading.Thread):
try:
line = b"".join(self.line_accumulator).decode('ascii')
self._parser.parse_message(line)
- now = datetime.datetime.utcnow()
+ now = time.time()
try:
if config.CACHE_FILE:
try:
with open(config.CACHE_FILE) as fd:
hist = json.load(fd)
- except FileNotFoundError:
+ except:
hist = []
- hist = [h for h in hist if h['ts'] + datetime.timedelta(seconds=config.CACHE_MAX_AGE) > now]
+ hist = [h for h in hist if h['ts'] + config.CACHE_MAX_AGE > now]
hist.append({'ts': now, 'line': line.strip()})
with open(config.CACHE_FILE, 'w') as fd:
json.dump(hist, fd)