More changes related to running on new kiosk.house.
authorScott Gasch <[email protected]>
Sun, 7 Nov 2021 05:42:36 +0000 (22:42 -0700)
committerScott Gasch <[email protected]>
Sun, 7 Nov 2021 05:42:36 +0000 (22:42 -0700)
constants.py
generic_news_rss_renderer.py
kiosk.py
seattletimes_rss_renderer.py
urbanist_renderer.py

index 4dc85217b2b892170fedb8a3630b523f08124784..a4f8e87b12671c5a953277aeee8562f8f7cc29b8 100644 (file)
@@ -1,7 +1,8 @@
 #!/usr/bin/env python3
 
 hostname = 'kiosk.house'
-pages_dir = "/var/www/kiosk/pages"
+pages_dir = '/var/www/html/kiosk'
+root_url = f'http://{hostname}/kiosk'
 
 refresh_period_sec = 22.0
 refresh_period_night_sec = 600.0
@@ -12,5 +13,5 @@ seconds_per_hour = seconds_per_minute * 60
 seconds_per_day = seconds_per_hour * 24
 
 myq_pagename = "myq_4_300.html"
-internal_stats_pagename = 'internal_stats_1_1000.html'
+internal_stats_pagename = 'internal-stats_1_1000.html'
 gcal_imminent_pagename = "hidden/gcal-imminent_0_none.html"
index e6d45335e47f87750fd17441f5f1d11af78065c9..149f8acb3aa9f163d195d42deec8e82b442da34f 100644 (file)
@@ -6,6 +6,8 @@ from dateutil.parser import parse
 import http.client
 import random
 import re
+import sys
+import traceback
 from typing import Dict, List, Optional, Union
 import xml.etree.ElementTree as ET
 
@@ -209,10 +211,10 @@ class generic_news_rss_renderer(renderer.debuggable_abstaining_renderer):
         for uri in self.feed_uris:
             if self.should_use_https():
                 self.debug_print("Fetching: https://%s%s" % (self.feed_site, uri))
-                self.conn = http.client.HTTPSConnection(self.feed_site, timeout=20)
+                self.conn = http.client.HTTPSConnection(self.feed_site, timeout=10)
             else:
                 self.debug_print("Fetching: http://%s%s" % (self.feed_site, uri))
-                self.conn = http.client.HTTPConnection(self.feed_site, timeout=20)
+                self.conn = http.client.HTTPConnection(self.feed_site, timeout=10)
             assert(self.conn is not None)
             self.conn.request(
                 "GET",
@@ -220,8 +222,8 @@ class generic_news_rss_renderer(renderer.debuggable_abstaining_renderer):
                 None,
                 {
                     "Accept": "*/*",
-                    "Cache-control": "max-age=59",
-                    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36",
+#                    "Cache-control": "max-age=50",
+#                    "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/27.0.1453.93 Safari/537.36",
                 },
             )
             try:
index 6d2fd4e00b5677c3bc8ea1728560ebb5912c6496..bd7137335ea25e5dbae0d8f39a9226c53c9bb19a 100755 (executable)
--- 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(
-        """
+"""
 <HEAD>
   <TITLE>Kitchen Kiosk</TITLE>
   <LINK rel="stylesheet" type="text/css" href="style.css">
@@ -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);
   })();
-</SCRIPT>
+  </SCRIPT>
 </HEAD>
-<BODY BGCOLOR="#%s">
-    <TABLE style="height:100%%; width:100%%" BORDER=0>
+""" % constants.root_url)
+    f.write(f'<BODY BGCOLOR="#{bgcolor}">')
+    f.write(
+"""
+    <TABLE style="height:100%; width:100%" BORDER=0>
     <TR HEIGHT=30>
         <TD ALIGN="left">
             <DIV id="date">&nbsp;</DIV>
@@ -462,13 +479,19 @@ def emit_wrapped(f,
         <TD COLSPAN=3>
             <DIV ID="content" STYLE="zoom: 1; visibility: hidden;">
               <!-- BEGIN main page contents. -->
-<!--#include virtual=\"%s\"-->
-              <!-- END main page contents. -->
+""")
+    f.write(f'<!--#include virtual="{filename}"-->')
+    f.write(
+"""
+            <!-- END main page contents. -->
             </DIV>
             <BR>
-            <DIV STYLE="position: absolute; top:1030px; width:99%%">
+            <DIV STYLE="position: absolute; top:1030px; width:99%">
             <P ALIGN="right">
-              <FONT SIZE=2 COLOR=#bbbbbb>%s @ %s ago.</FONT>
+""")
+    f.write(f'<FONT SIZE=2 COLOR=#bbbbbb>{pageid} @ {age} ago.</FONT>')
+    f.write(
+"""
             </P>
             <HR id="countdown" STYLE="width:0px;
                                       text-align:left;
@@ -482,17 +505,7 @@ def emit_wrapped(f,
         </TD>
     </TR>
     </TABLE>
-</BODY>"""
-        % (
-            bgcolor,
-            get_refresh_period(),
-            constants.hostname,
-            bgcolor,
-            filename,
-            pageid,
-            age,
-        )
-    )
+</BODY>""")
 
 
 def thread_invoke_renderers() -> None:
@@ -538,12 +551,13 @@ f'''
         with file_writer.file_writer(constants.internal_stats_pagename) as f:
             f.write(
 f'''
-<TABLE BORDER=0>
+<CENTER>
+<TABLE BORDER=0 WIDTH=95%>
     <TR>
-    <TH>Renderer Name</TH>
-    <TH>Last Run</TH>
-    <TH>Num Invocations</TH>
-    <TH>Render Latency</TH>
+    <TH><B>Renderer Name</B></TH>
+    <TH><B>Last Run</B></TH>
+    <TH><B>Num Invocations</B></TH>
+    <TH><B>Render Latency</B></TH>
     </TR>
 ''')
             for n, r in enumerate(renderer_catalog.get_renderers()):
@@ -571,10 +585,10 @@ f'''
                 f.write(
 f'''
     <TR>
-    <TD {style}>{name}</TD>
-    <TD {style}>{last}</TD>
-    <TD {style}><CENTER>{count}</CENTER></TD>
-    <TD {style}>p25={p25:5.2f}, p50={p50:5.2f}, p75={p75:5.2f}, p90={p90:5.2f}, p99={p99:5.2f}</TD>
+    <TD {style}>{name}&nbsp;</TD>
+    <TD {style}>&nbsp;{last}&nbsp;</TD>
+    <TD {style}><CENTER>&nbsp;{count}&nbsp;</CENTER></TD>
+    <TD {style}>&nbsp;p25={p25:5.2f}, p50={p50:5.2f}, p75={p75:5.2f}, p90={p90:5.2f}, p99={p99:5.2f}</TD>
     </TR>
 ''')
             f.write('</TABLE>')
index 13a9416e5e8b0884963540e3c098d19bf12a4441..2dd7cee3f96df856524da7825202e309ae299b18 100644 (file)
@@ -87,9 +87,9 @@ class seattletimes_rss_renderer(gnrss.generic_news_rss_renderer):
 
 
 # Test
-# x = seattletimes_rss_renderer({"Test", 123},
+#x = seattletimes_rss_renderer({"Test", 123},
 #                              "www.seattletimes.com",
-#                              [ "/life/feed/" ],
+#                              [ "/outdoors/feed/", '/live/feed/' ],
 #                              "nonnews")
-# x.periodic_render("Fetch News")
-# x.periodic_render("Shuffle News")
+#x.periodic_render("Fetch News")
+#x.periodic_render("Shuffle News")
index 36ef68b5e8b761d106a01d61bef991cb5d54e38c..a72f4d6399d61a43e155186972955664e6b22046 100644 (file)
@@ -44,7 +44,7 @@ class urbanist_renderer(gnrss.generic_news_rss_renderer):
     def item_is_interesting_for_headlines(
         self, title: str, description: str, item: xml.etree.ElementTree.Element
     ) -> bool:
-        return description.lower() != 'the urbanist'
+        return 'the urbanist' not in description.lower()
 
     def do_details(self) -> bool:
         return True