import file_writer
from bs4 import BeautifulSoup
import renderer
-import httplib
+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 = []
return "pollen"
def fetch_html(self):
- conn = httplib.HTTPConnection(self.site)
- conn.request(
- "GET",
- self.uri,
- None,
- {})
+ conn = http.client.HTTPConnection(self.site)
+ 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()
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:
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)
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, %s %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, %s %s</DIV>" % (count, desc, comment)
return text
def munge(self, raw):
<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>
</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
else:
raise error("Unknown operaiton")
-#test = pollen_count_renderer({"Test", 123})
+
+# test = pollen_count_renderer({"Test", 123})