aboutsummaryrefslogtreecommitdiffstats
path: root/glutte_serial_web.py
diff options
context:
space:
mode:
authorMatthias P. Braendli <matthias.braendli@mpb.li>2022-10-31 20:35:58 +0100
committerMatthias P. Braendli <matthias.braendli@mpb.li>2022-10-31 20:35:58 +0100
commit1546176881719a4fa7e63109f691eba32dd7bf85 (patch)
treecabfe48ece43578957c37d5400258d70401713ec /glutte_serial_web.py
parentd0c54a086b9ea67c067193b51dd8f16e8e75f454 (diff)
downloadglutte-serial-web-1546176881719a4fa7e63109f691eba32dd7bf85.tar.gz
glutte-serial-web-1546176881719a4fa7e63109f691eba32dd7bf85.tar.bz2
glutte-serial-web-1546176881719a4fa7e63109f691eba32dd7bf85.zip
Add history in json file
Diffstat (limited to 'glutte_serial_web.py')
-rwxr-xr-xglutte_serial_web.py15
1 files changed, 13 insertions, 2 deletions
diff --git a/glutte_serial_web.py b/glutte_serial_web.py
index a1a10ee..da61b1b 100755
--- a/glutte_serial_web.py
+++ b/glutte_serial_web.py
@@ -2,7 +2,7 @@
#
# The MIT License (MIT)
#
-# Copyright (c) 2020 Matthias P. Braendli, Maximilien Cuony
+# Copyright (c) 2022 Matthias P. Braendli, Maximilien Cuony
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -23,13 +23,15 @@
# SOFTWARE.
import time
+import json
from geventwebsocket.handler import WebSocketHandler
from gevent import pywsgi, Timeout
from time import sleep
-from flask import Flask, render_template, jsonify
+from flask import Flask, Response, render_template, jsonify
from flask_sockets import Sockets
import serialrx
import adsl
+import config
app = Flask(__name__)
sockets = Sockets(app)
@@ -41,6 +43,15 @@ adsl = adsl.ADSL(ser)
def index():
return render_template('index.html', last_lines=ser.get_last_lines())
+@app.route('/history')
+def history():
+ hist = []
+ if config.CACHE_FILE:
+ with open(config.CACHE_FILE) as fd:
+ hist = json.load(fd)
+ text = "\n".join(f"{entry['ts']} {entry['line']}" for entry in hist)
+ return Response(text, mimetype='text/plain')
+
@app.route('/stats')
def stats():
t_now = time.time()