X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=kiosk.py;fp=kiosk.py;h=bd7137335ea25e5dbae0d8f39a9226c53c9bb19a;hb=7eae23537dcc61565a24d5c957d4325b7337b63a;hp=6d2fd4e00b5677c3bc8ea1728560ebb5912c6496;hpb=f634dd36f1a66506fafcc7640cac333a37bdc469;p=kiosk.git diff --git a/kiosk.py b/kiosk.py index 6d2fd4e..bd71373 100755 --- a/kiosk.py +++ b/kiosk.py @@ -220,43 +220,48 @@ def thread_change_current(command_queue: Queue) -> None: if triggered: print("chooser[%s] - WE ARE TRIGGERED." % utils.timestamp()) - if page != page_history[0] or (swap_page_target - now < 10.0): + if page != page_history[0] or (swap_page_target - now) < 10.0: print( "chooser[%s] - EMERGENCY PAGE %s LOAD NEEDED" % (utils.timestamp(), page) ) - try: - with open(os.path.join(constants.pages_dir, "current.shtml"), "w") as f: - emit_wrapped(f, page, override_refresh_sec = 40, command = command) - page_history.insert(0, page) - page_history = page_history[0:10] - swap_page_target = now + 40 - except: - print("chooser[%s] - page does not exist?!" % (utils.timestamp())) - continue +# try: + current = os.path.join(constants.pages_dir, "current.shtml") + with open(current, "w") as f: + emit_wrapped(f, page, override_refresh_sec = 40, command = command) + print(f'Wrote {current}') + + page_history.insert(0, page) + page_history = page_history[0:10] + swap_page_target = now + 40 +# except: +# print("chooser[%s] - page does not exist?!" % (utils.timestamp())) +# continue # Also notify XMLHTTP clients that they need to refresh now. - path = os.path.join(constants.pages_dir, "reload_immediately.html") - with open(path, "w") as f: - f.write("Reload, suckers!") + emergency_file = os.path.join(constants.pages_dir, "reload_immediately.html") + with open(emergency_file, "w") as f: + f.write(f'Reload, suckers... you HAVE to see {page}!') + print(f'Causing immediate page reload with {emergency_file}...') # Fix this hack... maybe read the webserver logs and see if it # actually was picked up? - time.sleep(0.75) - os.remove(path) + time.sleep(3.0) + os.remove(emergency_file) + print(f'...and removed {emergency_file}') elif now >= swap_page_target: assert page != page_history[0] print("chooser[%s] - nominal choice of %s" % (utils.timestamp(), page)) - try: - with open(os.path.join(constants.pages_dir, "current.shtml"), "w") as f: - emit_wrapped(f, page) - page_history.insert(0, page) - page_history = page_history[0:10] - swap_page_target = now + constants.refresh_period_sec - except: - print("chooser[%s] - page does not exist?!" % (utils.timestamp())) - continue +# try: + with open(os.path.join(constants.pages_dir, "current.shtml"), "w") as f: + emit_wrapped(f, page) + page_history.insert(0, page) + page_history = page_history[0:10] + swap_page_target = now + constants.refresh_period_sec +# except: +# print("chooser[%s] - page does not exist?!" % (utils.timestamp())) +# continue time.sleep(1) @@ -298,7 +303,7 @@ def emit_wrapped(f, pageid = f'"{command}" -> {filename}' f.write( - """ +""" Kitchen Kiosk @@ -309,7 +314,7 @@ def emit_wrapped(f, function zoomScreen() { z = 285; do { - document.getElementById("content").style.zoom = z+"%%"; + document.getElementById("content").style.zoom = z+"%"; var body = document.body; var html = document.documentElement; var height = Math.max(body.scrollHeight, @@ -344,7 +349,9 @@ def emit_wrapped(f, } } } - +""") + f.write( +""" // Operate the clock at the top of the page. function runClock() { var today = new Date(); @@ -361,7 +368,9 @@ def emit_wrapped(f, document.getElementById("date").innerHTML = today.toDateString(); var t = setTimeout(function(){runClock()}, 1000); } - +""" % bgcolor) + f.write( +""" // Helper method for running the clock. function maybeAddZero(x) { return (x < 10) ? "0" + x : x; @@ -392,7 +401,10 @@ def emit_wrapped(f, addLoadEvent(zoomScreen); addLoadEvent(runClock); addLoadEvent(lateLoadImages); +""") + f.write( +""" // Runs the countdown line at the bottom and is responsible for // normal page reloads caused by the expiration of a timer. (function countdown() { @@ -422,14 +434,16 @@ def emit_wrapped(f, }); }, 50) })(); - +""" % get_refresh_period()) + f.write( +""" // Periodically checks for emergency reload events. (function poll() { setTimeout( function() { var xhr = new XMLHttpRequest(); xhr.open('GET', - 'http://%s/kiosk/pages/reload_immediately.html'); + '%s/reload_immediately.html'); xhr.onload = function() { if (xhr.status === 200) { @@ -443,10 +457,13 @@ def emit_wrapped(f, xhr.send(); }, 500); })(); - + - - +""" % constants.root_url) + f.write(f'') + f.write( +""" +
 
@@ -462,13 +479,19 @@ def emit_wrapped(f,

-
+

- %s @ %s ago. +""") + f.write(f'{pageid} @ {age} ago.') + f.write( +"""


""") def thread_invoke_renderers() -> None: @@ -538,12 +551,13 @@ f''' with file_writer.file_writer(constants.internal_stats_pagename) as f: f.write( f''' - +
+
- - - - + + + + ''') for n, r in enumerate(renderer_catalog.get_renderers()): @@ -571,10 +585,10 @@ f''' f.write( f''' - - - - + + + + ''') f.write('
Renderer NameLast RunNum InvocationsRender LatencyRenderer NameLast RunNum InvocationsRender Latency
{name}{last}
{count}
p25={p25:5.2f}, p50={p50:5.2f}, p75={p75:5.2f}, p90={p90:5.2f}, p99={p99:5.2f}{name}  {last} 
 {count} 
 p25={p25:5.2f}, p50={p50:5.2f}, p75={p75:5.2f}, p90={p90:5.2f}, p99={p99:5.2f}
')