From 2b9b0b77c646a5c3973624fe9aa115680d69f77d Mon Sep 17 00:00:00 2001 From: Scott Gasch Date: Mon, 13 Jul 2020 16:10:50 -0700 Subject: [PATCH] Make gkeep understand list indentation, tweaks to the countdown bar in kiosk.py (client side javascript) and add pubdate in generic RSS renderer. --- generic_news_rss_renderer.py | 4 ++-- gkeep_renderer.py | 38 +++++++++++++++++++++++++----------- kiosk.py | 29 +++++++++++++++++---------- 3 files changed, 48 insertions(+), 23 deletions(-) diff --git a/generic_news_rss_renderer.py b/generic_news_rss_renderer.py index 798c06c..5cf6e6c 100644 --- a/generic_news_rss_renderer.py +++ b/generic_news_rss_renderer.py @@ -238,8 +238,8 @@ a:active { if pubdate is not None: pubdate = self.munge_pubdate(pubdate) ts = parse(pubdate) - blurb += u" %s" % ( - ts.strftime("%b %d")) + blurb += u" %s" % ( + ts.strftime("%b %d")) if (description is not None and self.item_is_interesting_for_article(title, diff --git a/gkeep_renderer.py b/gkeep_renderer.py index 0285cf1..bad6830 100644 --- a/gkeep_renderer.py +++ b/gkeep_renderer.py @@ -37,7 +37,7 @@ class gkeep_renderer(renderer.debuggable_abstaining_renderer): return "gkeep" def periodic_render(self, key): - strikethrough = re.compile('\u2611([^\n]*)\n', re.UNICODE) + strikethrough = re.compile('(\u2611[^\n]*)\n', re.UNICODE) linkify = re.compile(r'.*(https?:\/\/\S+).*') self.keep.sync() @@ -51,18 +51,33 @@ class gkeep_renderer(renderer.debuggable_abstaining_renderer): contents = note.text + "\n" self.debug_print("Note title '%s'" % title) if contents != '' and not contents.isspace(): - contents = strikethrough.sub(r'` \1\n', contents) - contents = contents.replace('`', '\u2611') + contents = strikethrough.sub('', contents) + contents = contents.replace(u'\u2610', + u'
  •  ') + #self.debug_print("Note contents:\n%s" % contents) contents = linkify.sub(r'\1', contents) + individual_lines = contents.split("\n") num_lines = len(individual_lines) max_length = 0 + indent = 0 + contents = "" for x in individual_lines: length = len(x) if length > max_length: max_length = length - contents = contents.replace("\n", "
    \n") + spaces = len(x) - len(x.lstrip(' ')) + spaces /= 2 + x = x.lstrip(' ') + if spaces > indent: + x = "" + x + indent = spaces + contents = contents + x + "\n" + + individual_lines = contents.split("\n") color = note.color.name.lower() if color in list(self.colors_by_name.keys()): color = self.colors_by_name[color] @@ -71,7 +86,8 @@ class gkeep_renderer(renderer.debuggable_abstaining_renderer): f = file_writer.file_writer(filename) f.write("""

    %s

    @@ -81,20 +97,20 @@ a:link { color:#88bfbf; } (num_lines, max_length)) f.write("") f.write("\n") + f.write("\n") f.write("
    \n") - f.write("") + f.write("
      ") count = 0 for x in individual_lines: - f.write(x + "
      \n") + f.write(x + "\n") count += 1 if count == num_lines / 2: - f.write("
    \n") - f.write("") - f.write("
    \n"); + f.write("
      ") + f.write("
    \n"); else: self.debug_print("%d lines (max=%d chars): one column" % (num_lines, max_length)) - f.write("%s" % contents) + f.write("
      %s
    " % contents) f.write("") f.close() else: diff --git a/kiosk.py b/kiosk.py index 5bc28cd..fd50910 100755 --- a/kiosk.py +++ b/kiosk.py @@ -172,29 +172,28 @@ def emit_wrapped(f, filename): return new Promise(resolve => setTimeout(resolve, milliseconds)) } - var loaded = false; var loadedDate = new Date(); addLoadEvent(zoomScreen); addLoadEvent(runClock); addLoadEvent(lateLoadImages); - addLoadEvent(function() { - loaded = true; - }); - // Reload the page after a certain amount of time has passed or - // immediately if told to do so. - (function poll() { + // Runs the countdown line at the bottom and is responsible for + // normal page reloads caused by the expiration of a timer. + (function countdown() { setTimeout( function() { var now = new Date(); var deltaMs = now.getTime() - loadedDate.getTime(); - var totalMs = %d; var remainingMs = (totalMs - deltaMs); + if (remainingMs > 0) { var hr = document.getElementById("countdown"); - var width = (remainingMs / totalMs) * 100.0; + var width = (remainingMs / (totalMs - 5000)) * 100.0; + if (width > 100) { + width = 100; + } hr.style.width = " ".concat(width, "%%"); hr.style.backgroundColor = "maroon"; } else { @@ -202,7 +201,17 @@ def emit_wrapped(f, filename): window.location.reload(); } - // Also reload immediately if told to do so. + // Brief sleep before doing it all over again. + sleep(50).then(() => { + countdown(); + }); + }, 50) + })(); + + // Periodically checks for emergency reload events. + (function poll() { + setTimeout( + function() { var xhr = new XMLHttpRequest(); xhr.open('GET', 'http://wannabe.house/kiosk/pages/reload_immediately.html'); -- 2.45.2