Update cabin camera URL.
[kiosk.git] / pollen_renderer.py
index 745ad52a5e50465f0fda1f124bc0d059b1fe2815..a8f6170492b0ea99c0fa4317f71d41be8d72b610 100644 (file)
@@ -4,11 +4,12 @@ import renderer
 import http.client
 import re
 
+
 class pollen_count_renderer(renderer.debuggable_abstaining_renderer):
     def __init__(self, name_to_timeout_dict):
         super(pollen_count_renderer, self).__init__(name_to_timeout_dict, False)
-        self.site = 'www.nwasthma.com'
-        self.uri = '/pollen/pollen-count/'
+        self.site = "www.nwasthma.com"
+        self.uri = "/pollen/pollen-count/"
         self.trees = []
         self.grasses = []
         self.weeds = []
@@ -18,16 +19,15 @@ class pollen_count_renderer(renderer.debuggable_abstaining_renderer):
 
     def fetch_html(self):
         conn = http.client.HTTPConnection(self.site)
-        conn.request(
-                "GET",
-                self.uri,
-                None,
-                {})
+        conn.request("GET", self.uri, None, {})
         response = conn.getresponse()
         if response.status != 200:
-            print(('Connection to %s/%s failed, status %d' % (self.site,
-                                                             self.uri,
-                                                             response.status)))
+            print(
+                (
+                    "Connection to %s/%s failed, status %d"
+                    % (self.site, self.uri, response.status)
+                )
+            )
             return False
         return response.read()
 
@@ -35,7 +35,7 @@ class pollen_count_renderer(renderer.debuggable_abstaining_renderer):
         desc = ""
         color = "#00d000"
         if tr != None and tr.string != None:
-            desc = tr.string.encode('utf-8')
+            desc = tr.string.encode("utf-8")
             if "edium" in desc:
                 color = "#a0a000"
             elif "igh" in desc:
@@ -44,7 +44,7 @@ class pollen_count_renderer(renderer.debuggable_abstaining_renderer):
         count = 0
         if tc != None and tc.string != None:
             try:
-                count = int(tc.string.encode('utf-8'))
+                count = int(tc.string.encode("utf-8"))
             except:
                 count = 0
         proportion = float(count) / float(maximum)
@@ -52,14 +52,18 @@ class pollen_count_renderer(renderer.debuggable_abstaining_renderer):
 
         comment = ""
         if tcomment != None and tcomment.string != None:
-            comment = "%s" % (tcomment.string.encode('utf-8'))
+            comment = "%s" % (tcomment.string.encode("utf-8"))
 
         # Label:
         text = text + '<TR><TD WIDTH=10%% STYLE="font-size: 22pt">%s:</TD>' % (kind)
 
         # Bar graph with text in it (possibly overspilling):
-        text = text + '<TD HEIGHT=80><DIV STYLE="width: %d; height: 80; overflow: visible; background-color: %s; font-size: 16pt">' % (width, color)
-        text = text + 'count=%d,&nbsp;%s&nbsp;%s</DIV>' % (count, desc, comment)
+        text = (
+            text
+            + '<TD HEIGHT=80><DIV STYLE="width: %d; height: 80; overflow: visible; background-color: %s; font-size: 16pt">'
+            % (width, color)
+        )
+        text = text + "count=%d,&nbsp;%s&nbsp;%s</DIV>" % (count, desc, comment)
         return text
 
     def munge(self, raw):
@@ -71,41 +75,42 @@ class pollen_count_renderer(renderer.debuggable_abstaining_renderer):
 <CENTER>
 <TABLE BODER WIDTH=800>"""
         date = "<CENTER><B>Unknown Date</B></CENTER>"
-        for x in soup.find_all('p'):
+        for x in soup.find_all("p"):
             if x == None or x.string == None:
                 continue
-            txt = x.string.encode('utf-8')
+            txt = x.string.encode("utf-8")
             m = re.match("[0-9][0-9].[0-9][0-9].20[0-9][0-9]", txt)
             if m != None:
                 date = "<CENTER><B>%s</B></CENTER>" % (txt)
-                y = x.find_next_sibling('p')
+                y = x.find_next_sibling("p")
                 if y != None and y.string != None:
-                    txt = y.string.encode('utf-8')
+                    txt = y.string.encode("utf-8")
                     date = date + "<BR>%s<HR>" % txt
-        text = text + '<TR><TD COLSPAN=3 STYLE="font-size:16pt">%s</TD></TR>\n' % (
-            date)
+        text = text + '<TR><TD COLSPAN=3 STYLE="font-size:16pt">%s</TD></TR>\n' % (date)
 
-        trees = soup.find('td', text=re.compile('[Tt]rees:'))
+        trees = soup.find("td", text=re.compile("[Tt]rees:"))
         if trees != None:
-            tc = trees.find_next_sibling('td')
-            tr = tc.find_next_sibling('td')
-            tcomment = tr.find_next_sibling('td')
+            tc = trees.find_next_sibling("td")
+            tr = tc.find_next_sibling("td")
+            tcomment = tr.find_next_sibling("td")
             text = self.append_crap(text, tc, tr, tcomment, "Trees", 650)
 
-        grasses = soup.find('td', text=re.compile('[Gg]rasses:'))
+        grasses = soup.find("td", text=re.compile("[Gg]rasses:"))
         if grasses != None:
-            gc = grasses.find_next_sibling('td')
-            gr = gc.find_next_sibling('td')
-            gcomment = gr.find_next_sibling('td')
+            gc = grasses.find_next_sibling("td")
+            gr = gc.find_next_sibling("td")
+            gcomment = gr.find_next_sibling("td")
             text = self.append_crap(text, gc, gr, gcomment, "Grasses", 35)
 
-        weeds = soup.find('td', text=re.compile('[Ww]eeds:'))
+        weeds = soup.find("td", text=re.compile("[Ww]eeds:"))
         if weeds != None:
-            wc = weeds.find_next_sibling('td')
-            wr = wc.find_next_sibling('td')
-            wcomment = wr.find_next_sibling('td')
+            wc = weeds.find_next_sibling("td")
+            wr = wc.find_next_sibling("td")
+            wcomment = wr.find_next_sibling("td")
             text = self.append_crap(text, wc, wr, wcomment, "Weeds", 25)
-        text = text + """
+        text = (
+            text
+            + """
 <TR>
   <TD COLSPAN=3 STYLE="font-size:16pt">
 <HR>
@@ -118,12 +123,13 @@ class pollen_count_renderer(renderer.debuggable_abstaining_renderer):
 </TR>
 </TABLE>
 </CENTER>"""
+        )
         return text
 
     def poll_pollen(self):
         raw = self.fetch_html()
         cooked = self.munge(raw)
-        f = file_writer.file_writer('pollen_4_360.html')
+        f = file_writer.file_writer("pollen_4_360.html")
         f.write(cooked)
         f.close()
         return True
@@ -135,4 +141,5 @@ class pollen_count_renderer(renderer.debuggable_abstaining_renderer):
         else:
             raise error("Unknown operaiton")
 
-#test = pollen_count_renderer({"Test", 123})
+
+# test = pollen_count_renderer({"Test", 123})