X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=reuters_rss_renderer.py;h=5525e2e1d14935aadd4c91bd15668ca89daecf3c;hb=8d27ea3f0b6f35a71a80f19bfe12f0e3a838dc5b;hp=e84b3cc3834ec9bd798f24e4be476dd6c1132a25;hpb=75b27cc68871343681f01e3f5b04cae84b1b7b2a;p=kiosk.git diff --git a/reuters_rss_renderer.py b/reuters_rss_renderer.py index e84b3cc..5525e2e 100644 --- a/reuters_rss_renderer.py +++ b/reuters_rss_renderer.py @@ -11,6 +11,7 @@ import re import sets import xml.etree.ElementTree as ET + class reuters_rss_renderer(renderer.debuggable_abstaining_renderer): def __init__(self, name_to_timeout_dict, feed_site, feed_uris, page): super(reuters_rss_renderer, self).__init__(name_to_timeout_dict, False) @@ -31,7 +32,7 @@ class reuters_rss_renderer(renderer.debuggable_abstaining_renderer): elif key == "Shuffle News": return self.shuffle_news() else: - raise error('Unexpected operation') + raise error("Unexpected operation") def shuffle_news(self): headlines = page_builder.page_builder() @@ -43,7 +44,7 @@ class reuters_rss_renderer(renderer.debuggable_abstaining_renderer): return False for msg in subset: headlines.add_item(msg) - f = file_writer.file_writer('reuters-%s_4_none.html' % self.page) + f = file_writer.file_writer("reuters-%s_4_none.html" % self.page) headlines.render_html(f) f.close() @@ -52,13 +53,13 @@ class reuters_rss_renderer(renderer.debuggable_abstaining_renderer): details.set_title("%s" % self.page) subset = self.details.subset(1) if subset is None: - self.debug_print("Not enough details to choose from."); + self.debug_print("Not enough details to choose from.") return False for msg in subset: blurb = msg blurb += "\n" details.add_item(blurb) - g = file_writer.file_writer('reuters-details-%s_6_none.html' % self.page) + g = file_writer.file_writer("reuters-details-%s_6_none.html" % self.page) details.render_html(g) g.close() return True @@ -71,59 +72,64 @@ class reuters_rss_renderer(renderer.debuggable_abstaining_renderer): for uri in self.feed_uris: self.conn = http.client.HTTPConnection(self.feed_site) - self.conn.request( - "GET", - uri, - None, - {"Accept-Charset": "utf-8"}) + self.conn.request("GET", uri, None, {"Accept-Charset": "utf-8"}) response = self.conn.getresponse() if response.status != 200: - print(("%s: RSS fetch_news error, response: %d" % (self.page, - response.status))) + print( + ( + "%s: RSS fetch_news error, response: %d" + % (self.page, response.status) + ) + ) self.debug_print(response.read()) return False rss = ET.fromstring(response.read()) channel = rss[0] for item in channel.getchildren(): - title = item.findtext('title') - if (title is None or - "euters" in title or - title == "Editor's Choice" or - self.filter.contains_bad_words(title)): + title = item.findtext("title") + if ( + title is None + or "euters" in title + or title == "Editor's Choice" + or self.filter.contains_bad_words(title) + ): continue - pubdate = item.findtext('pubDate') - image = item.findtext('image') - descr = item.findtext('description') + pubdate = item.findtext("pubDate") + image = item.findtext("image") + descr = item.findtext("description") if descr is not None: - descr = re.sub('<[^>]+>', '', descr) + descr = re.sub("<[^>]+>", "", descr) blurb = """
%s' % title
+ blurb += (
+ '\n'
+ % image
+ )
+ blurb += "
%s" % title
if pubdate != None:
# Thu, 04 Jun 2015 08:16:35 GMT|-0400
- pubdate = pubdate.rsplit(' ', 1)[0]
- dt = datetime.datetime.strptime(pubdate,
- '%a, %d %b %Y %H:%M:%S')
+ pubdate = pubdate.rsplit(" ", 1)[0]
+ dt = datetime.datetime.strptime(pubdate, "%a, %d %b %Y %H:%M:%S")
if dt < oldest:
continue
- blurb += dt.strftime(" (%a %b %d)")
+ blurb += dt.strftime(
+ " (%a %b %d)"
+ )
if descr is not None:
longblurb = blurb
longblurb += "
"
longblurb += descr
longblurb += "