More work on generic RSS renderer base class. Make the kiosk have a countdown
[kiosk.git] / generic_news_rss_renderer.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>"