18f300b2e1b7aed53bdb412ec975e0c9eeab891e
[kiosk.git] / stevens_renderer.py
1 import renderer
2 import file_writer
3 import http.client
4 import xml.etree.ElementTree as ET
5
6 class stevens_pass_conditions_renderer(renderer.debuggable_abstaining_renderer):
7     def __init__(self, name_to_timeout_dict, feed_site, feed_uris):
8         super(stevens_pass_conditions_renderer, self).__init__(
9             name_to_timeout_dict, False)
10         self.feed_site = feed_site
11         self.feed_uris = feed_uris
12
13     def debug_prefix(self):
14         return "stevens"
15
16     def periodic_render(self, key):
17         f = file_writer.file_writer('stevens-conditions_1_86400.html')
18         for uri in self.feed_uris:
19             self.conn = http.client.HTTPSConnection(self.feed_site)
20             self.conn.request(
21                 "GET",
22                 uri,
23                 None,
24                 {"Accept-Charset": "utf-8"})
25             response = self.conn.getresponse()
26             if response.status == 200:
27                 raw = response.read()
28                 rss = ET.fromstring(raw)
29                 channel = rss[0]
30                 for item in channel.getchildren():
31                     if item.tag == "title":
32                         f.write("<h1>%s</h1><hr>" % item.text)
33                         f.write('<IMG WIDTH=512 ALIGN=RIGHT HEIGHT=382 SRC="https://images.wsdot.wa.gov/nc/002vc06430.jpg?t=637059938785646824" style="padding:8px;">')
34                     elif item.tag == "item":
35                         for x in item.getchildren():
36                             if x.tag == "description":
37                                 text = x.text
38                                 text = text.replace("<strong>Stevens Pass US2</strong><br/>", "")
39                                 text = text.replace("<br/><br/>", "<BR>")
40                                 text = text.replace("<strong>Elevation Meters:</strong>1238<BR>", "")
41                                 f.write('<P>\n%s\n' % text)
42                 f.close()
43                 return True
44         f.close()
45         return False