More work on generic RSS renderer base class. Make the kiosk have a countdown
authorScott Gasch <[email protected]>
Sun, 12 Jul 2020 17:33:45 +0000 (10:33 -0700)
committerScott Gasch <[email protected]>
Sun, 12 Jul 2020 17:33:45 +0000 (10:33 -0700)
line.

generic_news_rss_renderer.py
google_news_rss_renderer.py
kiosk.py

index 4db466957456095148d1793a772e0069b02ae32b..798c06c90962d001a87ed93f1a9a2114a3ccbc88 100644 (file)
@@ -31,6 +31,12 @@ class generic_news_rss_renderer(renderer.debuggable_abstaining_renderer):
     def get_details_page_prefix(self):
         pass
 
+    def get_headlines_page_priority(self):
+        return "4"
+
+    def get_details_page_priority(self):
+        return "6"
+
     def should_use_https(self):
         pass
 
@@ -62,11 +68,17 @@ class generic_news_rss_renderer(renderer.debuggable_abstaining_renderer):
     def munge_image(self, image):
         return image
 
+    def find_pubdate(self, item):
+        return item.findtext('pubDate')
+
+    def munge_pubdate(self, pubdate):
+        return pubdate
+
     def item_is_interesting_for_headlines(self, title, description, item):
         return True
 
     def is_item_older_than_n_days(self, item, n):
-        pubdate = item.findtext('pubDate')
+        pubdate = self.find_pubdate(item)
         if pubdate is not None:
             pubdate = parse(pubdate)
             tzinfo = pubdate.tzinfo
@@ -100,23 +112,24 @@ class generic_news_rss_renderer(renderer.debuggable_abstaining_renderer):
         headlines.set_custom_html("""
 <STYLE>
 a:link {
-  color: maroon;
+  color: black;
   text-decoration: none;
   font-weight: bold;
 }
 a:visited {
-  color: maroon;
+  color: black;
   text-decoration: none;
   font-weight: bold;
 }
 a:active {
-  color: maroon;
+  color: black;
   text-decoration: none;
   font-weight: bold;
 }
 </STYLE>""")
-        f = file_writer.file_writer('%s_4_none.html' % (
-            self.get_headlines_page_prefix()))
+        f = file_writer.file_writer('%s_%s_none.html' % (
+            self.get_headlines_page_prefix(),
+            self.get_headlines_page_priority()))
         headlines.render_html(f)
         f.close()
 
@@ -125,17 +138,17 @@ a:active {
         details.set_custom_html("""
 <STYLE>
 a:link {
-  color: maroon;
+  color: black;
   text-decoration: none;
   font-weight: bold;
 }
 a:visited {
-  color: maroon;
+  color: black;
   text-decoration: none;
   font-weight: bold;
 }
 a:active {
-  color: maroon;
+  color: black;
   text-decoration: none;
   font-weight: bold;
 }
@@ -149,8 +162,9 @@ a:active {
             blurb = msg
             blurb += u'</TD>'
             details.add_item(blurb)
-        g = file_writer.file_writer('%s_6_none.html' % (
-            self.get_details_page_prefix()))
+        g = file_writer.file_writer('%s_%s_none.html' % (
+            self.get_details_page_prefix(),
+            self.get_details_page_priority()))
         details.render_html(g)
         g.close()
         return True
@@ -208,9 +222,6 @@ a:active {
                     self.debug_print('Found bad words in item "%s"' % title)
                     continue
 
-                #print u"Title: %s\nDescription: %s\nLink: %s\nImage: %s\n" % (
-                #    title, description, link, image)
-
                 blurb = u"""<DIV style="padding:8px;
                                  font-size:34pt;
                                  -webkit-column-break-inside:avoid;">"""
@@ -223,11 +234,19 @@ a:active {
                 else:
                     blurb += u'<P><B><A HREF="%s">%s</A></B>' % (link, title)
 
+                pubdate = self.find_pubdate(item)
+                if pubdate is not None:
+                    pubdate = self.munge_pubdate(pubdate)
+                    ts = parse(pubdate)
+                    blurb += u" <FONT COLOR=#cccccc>%s</FONT>" % (
+                        ts.strftime("%b %d"))
+
                 if (description is not None and
                     self.item_is_interesting_for_article(title,
                                                          description,
                                                          item)):
                     longblurb = blurb
+
                     longblurb += u"<BR>"
                     longblurb += description
                     longblurb += u"</DIV>"
index 334f10d96345fd63165d9d8bf1a4a39809bdc5ba..7ca37e880666b139cbbca1e5cfdf7c9da7e1b62f 100644 (file)
@@ -31,7 +31,11 @@ class google_news_rss_renderer(generic_news_rss_renderer.generic_news_rss_render
         soup = BeautifulSoup(description)
         for a in soup.findAll('a'):
             del a['href']
-        return str(soup)
+        descr = str(soup)
+        if len(descr) > 400:
+            descr = descr[:400]
+            descr = descr + " [...]"
+        return descr
 
     def find_image(self, item):
         return None
index 0c8cce09f3a6b0bc92a636ada326cee71eb27cf7..5bc28cda4843aba9428c20bf162109173b8ac1eb 100755 (executable)
--- a/kiosk.py
+++ b/kiosk.py
@@ -190,12 +190,19 @@ def emit_wrapped(f, filename):
         var now = new Date();
         var deltaMs = now.getTime() - loadedDate.getTime();
 
-        // Reload unconditionally after 22 sec.
-        if (deltaMs > %d) {
+        var totalMs = %d;
+        var remainingMs = (totalMs - deltaMs);
+        if (remainingMs > 0) {
+          var hr = document.getElementById("countdown");
+          var width = (remainingMs / totalMs) * 100.0;
+          hr.style.width = " ".concat(width, "%%");
+          hr.style.backgroundColor = "maroon";
+        } else {
+          // Reload unconditionally after 22 sec.
           window.location.reload();
         }
 
-        // Reload immediately if told.
+        // Also reload immediately if told to do so.
         var xhr = new XMLHttpRequest();
         xhr.open('GET',
                  'http://wannabe.house/kiosk/pages/reload_immediately.html');
@@ -238,6 +245,14 @@ def emit_wrapped(f, filename):
             <P ALIGN="right">
                 <FONT SIZE=2 COLOR=#bbbbbb>%s @ %s ago.</FONT>
             </P>
+            <HR id="countdown" STYLE="width:0px;
+                                      text-align:left;
+                                      border:none;
+                                      margin-top:0;
+                                      margin-left:0;
+                                      margin-bottom:2px;
+                                      height:5px;
+                                      background-color:#ffffff;">
         </TD>
     </TR>
     </TABLE>