From bd326d0211881ad532ab0d590a94c40af3698a9f Mon Sep 17 00:00:00 2001 From: Ruben van de Ven Date: Fri, 1 Nov 2019 19:09:20 +0100 Subject: [PATCH] Statuspage changes --- sorteerhoed/webserver.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/sorteerhoed/webserver.py b/sorteerhoed/webserver.py index 76eebea..74d87e3 100644 --- a/sorteerhoed/webserver.py +++ b/sorteerhoed/webserver.py @@ -15,6 +15,7 @@ from sorteerhoed.Signal import Signal import httpagentparser import geoip2.database import queue +import datetime logger = logging.getLogger("sorteerhoed").getChild("webserver") @@ -172,7 +173,8 @@ class StatusWebSocketHandler(tornado.websocket.WebSocketHandler): connections = set() queue = queue.Queue() - def initialize(self): + def initialize(self, statusPage): + self.statusPage = statusPage pass def check_origin(self, origin): @@ -184,6 +186,11 @@ class StatusWebSocketHandler(tornado.websocket.WebSocketHandler): # the client connected def open(self, p = None): self.__class__.connections.add(self) + for prop, value in enumerate(self.statusPage.__dict__): + self.write_message(json.dumps({ + 'property': prop, + 'value': value.isoformat(timespec='seconds') if type(value) is datetime.datetime else value + })) # client disconnected @@ -203,7 +210,7 @@ class StatusWebSocketHandler(tornado.websocket.WebSocketHandler): for connection in cls.connections: connection.write_message(json.dumps({ 'property': prop, - 'value': value + 'value': value.isoformat(timespec='seconds') if type(value) is datetime.datetime else value })) def strokes2D(strokes): @@ -406,7 +413,7 @@ class Server: 'eventQ': self.eventQ, 'store': self.store, }), - (r"/status/ws", StatusWebSocketHandler), + (r"/status/ws", StatusWebSocketHandler, dict(statusPage = self.statusPage)), (r"/draw", DrawPageHandler, dict( store = self.store,