- def periodic_render(self, key):
- f = file_writer.file_writer("stevens-conditions_1_86400.html")
- for uri in self.feed_uris:
- self.conn = http.client.HTTPSConnection(self.feed_site)
- self.conn.request("GET", uri, None, {"Accept-Charset": "utf-8"})
- response = self.conn.getresponse()
- if response.status == 200:
- raw = response.read()
- rss = ET.fromstring(raw)
- channel = rss[0]
- for item in channel.getchildren():
- if item.tag == "title":
- f.write("<h1>%s</h1><hr>" % item.text)
- f.write(
- '<IMG WIDTH=512 ALIGN=RIGHT HEIGHT=382 SRC="https://images.wsdot.wa.gov/nc/002vc06430.jpg?t=637059938785646824" style="padding:8px;">'
- )
- elif item.tag == "item":
- for x in item.getchildren():
- if x.tag == "description":
- text = x.text
- text = text.replace(
- "<strong>Stevens Pass US2</strong><br/>", ""
- )
- text = text.replace("<br/><br/>", "<BR>")
- text = text.replace(
- "<strong>Elevation Meters:</strong>1238<BR>", ""
- )
- f.write("<P>\n%s\n" % text)
- f.close()
- return True
- f.close()
+ def periodic_render(self, key: str) -> bool:
+ with file_writer.file_writer("stevens-conditions_1_86400.html") as f:
+ for uri in self.feed_uris:
+ self.conn = http.client.HTTPSConnection(self.feed_site)
+ self.conn.request("GET", uri, None, {"Accept-Charset": "utf-8"})
+ response = self.conn.getresponse()
+ if response.status == 200:
+ raw = response.read()
+ rss = ET.fromstring(raw)
+ channel = rss[0]
+ for item in channel.getchildren():
+ if item.tag == "title":
+ f.write(f"<h1>{item.text}</h1><hr>")
+ f.write(
+ '<IMG WIDTH=512 ALIGN=RIGHT HEIGHT=382 SRC="https://images.wsdot.wa.gov/nc/002vc06430.jpg?t=637059938785646824" style="padding:8px;">'
+ )
+ elif item.tag == "item":
+ for x in item.getchildren():
+ if x.tag == "description":
+ text = x.text
+ if text is not None:
+ text = text.replace(
+ "<strong>Stevens Pass US2</strong><br/>", ""
+ )
+ text = text.replace("<br/><br/>", "<BR>")
+ text = text.replace(
+ "<strong>Elevation Meters:</strong>1238<BR>", ""
+ )
+ else:
+ text = ""
+ f.write(f"<P>\n{text}\n")
+ return True