6 from typing import Dict
12 logger = logging.getLogger(__file__)
15 class stevens_renderer(renderer.abstaining_renderer):
16 URL = 'https://wsdot.com/Travel/Real-time/Service/api/MountainPass/Details/10'
18 def __init__(self, name_to_timeout_dict: Dict[str, int]) -> None:
19 super().__init__(name_to_timeout_dict)
21 def render_conditions(mp: Dict[str, str], conditions: Dict[str, str]) -> str:
25 <TD WIDTH="150"><FONT SIZE=+2><B>Temp:</B></FONT></TD>
26 <TD><FONT SIZE=+2>{conditions['temperature']}°{conditions['temperatureUnit'][0]}</FONT></TD>
29 <TD><FONT SIZE=+2><B>Weather:</B></FONT></TD>
30 <TD><FONT SIZE=+2>{conditions['weather']}</FONT></TD>
33 <TD><FONT SIZE=+2><B>Roadway:</B></FONT></TD>
34 <TD><FONT SIZE=+2>{conditions['roadCondition']}</FONT></TD>
36 if 'restrictionOne' in conditions and 'restrictionTwo' in conditions:
39 <TD><FONT SIZE=+2><B>Restrictions:</B></FONT></TD>
42 msg = conditions['restrictionOne'].get('publicPage', 'no restrictions')
43 if msg.lower() != 'no restrictions':
45 msg = conditions['restrictionTwo'].get('publicPage', 'no restrictions')
46 if msg.lower() != 'no restrictions':
50 <U>{conditions['restrictionOne']['travelDirectionName']}:</U>
51 {conditions['restrictionOne']['publicPage']} <BR>
52 <U>{conditions['restrictionTwo']['travelDirectionName']}:</U>
53 {conditions['restrictionTwo']['publicPage']}'''
55 msg = conditions['restrictionOne'].get('publicPage', 'no restrictions')
56 if msg.lower() != 'no restrictions':
58 <U>{conditions['restrictionOne']['travelDirectionName']}:</U>
59 {conditions['restrictionOne']['publicPage']}<BR>'''
62 <U>{conditions['restrictionTwo']['travelDirectionName']}:</U>
63 {conditions['restrictionTwo']['publicPage']}<BR>'''
65 ret += '''None.<BR>'''
66 ret += '</FONT></TD></TR></TABLE>'
69 def render_forecast(forecasts: Dict[str, str]) -> str:
71 fc = forecasts['forecast']['forecastData']
72 for n, f in enumerate(fc):
75 color = ' BGCOLOR="#dfefff"'
78 <TD WIDTH="150" valign="top" {color}><B>{f['periodText']}</B></TD>
79 <TD{color}>{f['forecastText']}</TD>
84 def render_image(cameras: Dict[str, str]) -> str:
85 for camera in cameras:
86 if camera['cameraId'] == 8063:
89 <A HREF='https://wsdot.com/travel/real-time/mountainpasses/Stevens'>
90 <IMG SRC={camera['cameraUrl']} WIDTH={camera['width'] * 1.75}>
93 <I>{camera['cameraLabel']} ({camera['direction']})</I>
97 def periodic_render(self, unused: str) -> bool:
98 page = requests.get(stevens_renderer.URL)
99 if page.status_code == 200:
100 contents = json.loads(page.content)
101 mp = contents['mountainPass']
102 conditions = contents['condition']
103 cameras = contents['cameras']
104 forecasts = contents['stationForecasts'][0]
105 with file_writer.file_writer('stevens-conditions_5_3000.html') as f:
107 <H1>Stevens Pass Conditions:</H1>
112 {stevens_renderer.render_conditions(mp, conditions)}
115 {stevens_renderer.render_image(cameras)}
120 {stevens_renderer.render_forecast(forecasts)}
128 #test = stevens_renderer({"Test", 123})
129 #test.periodic_render("Test")