Statuspage changes

This commit is contained in:
Ruben van de Ven 2019-11-01 19:09:20 +01:00
parent 7fae18b6d8
commit bd326d0211

View file

@ -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,