import renderer
-logger = logging.getLogger(__file__)
+logger = logging.getLogger(__name__)
class stevens_renderer(renderer.abstaining_renderer):
- URL = 'https://wsdot.com/Travel/Real-time/Service/api/MountainPass/Details/10'
+ URL = "https://wsdot.com/Travel/Real-time/Service/api/MountainPass/Details/10"
def __init__(self, name_to_timeout_dict: Dict[str, int]) -> None:
super().__init__(name_to_timeout_dict)
def render_conditions(mp: Dict[str, str], conditions: Dict[str, str]) -> str:
- ret = f'''
+ ret = f"""
<TABLE>
<TR>
<TD WIDTH="150"><FONT SIZE=+2><B>Temp:</B></FONT></TD>
<TR>
<TD><FONT SIZE=+2><B>Roadway:</B></FONT></TD>
<TD><FONT SIZE=+2>{conditions['roadCondition']}</FONT></TD>
-</TR>'''
- if 'restrictionOne' in conditions and 'restrictionTwo' in conditions:
- ret += '''
+</TR>"""
+ if "restrictionOne" in conditions and "restrictionTwo" in conditions:
+ ret += """
<TR>
<TD><FONT SIZE=+2><B>Restrictions:</B></FONT></TD>
- <TD><FONT SIZE=+2>'''
+ <TD><FONT SIZE=+2>"""
count = 0
- msg = conditions['restrictionOne'].get('publicPage', 'no restrictions')
- if msg.lower() != 'no restrictions':
+ msg = conditions["restrictionOne"].get("publicPage", "no restrictions")
+ if msg.lower() != "no restrictions":
count += 1
- msg = conditions['restrictionTwo'].get('publicPage', 'no restrictions')
- if msg.lower() != 'no restrictions':
+ msg = conditions["restrictionTwo"].get("publicPage", "no restrictions")
+ if msg.lower() != "no restrictions":
count += 1
if count == 2:
- ret += f'''
+ ret += f"""
<U>{conditions['restrictionOne']['travelDirectionName']}:</U>
{conditions['restrictionOne']['publicPage']} <BR>
<U>{conditions['restrictionTwo']['travelDirectionName']}:</U>
- {conditions['restrictionTwo']['publicPage']}'''
+ {conditions['restrictionTwo']['publicPage']}"""
elif count == 1:
- msg = conditions['restrictionOne'].get('publicPage', 'no restrictions')
- if msg.lower() != 'no restrictions':
- ret += f'''
+ msg = conditions["restrictionOne"].get("publicPage", "no restrictions")
+ if msg.lower() != "no restrictions":
+ ret += f"""
<U>{conditions['restrictionOne']['travelDirectionName']}:</U>
- {conditions['restrictionOne']['publicPage']}<BR>'''
+ {conditions['restrictionOne']['publicPage']}<BR>"""
else:
- ret += f'''
+ ret += f"""
<U>{conditions['restrictionTwo']['travelDirectionName']}:</U>
- {conditions['restrictionTwo']['publicPage']}<BR>'''
+ {conditions['restrictionTwo']['publicPage']}<BR>"""
else:
- ret += '''None.<BR>'''
- ret += '</FONT></TD></TR></TABLE>'
+ ret += """None.<BR>"""
+ ret += "</FONT></TD></TR></TABLE>"
return ret
def render_forecast(forecasts: Dict[str, str]) -> str:
- ret = '<TABLE>'
- fc = forecasts['forecast']['forecastData']
+ ret = "<TABLE>"
+ fc = forecasts["forecast"]["forecastData"]
for n, f in enumerate(fc):
- color = ''
+ color = ""
if n % 2 == 0:
color = ' BGCOLOR="#dfefff"'
- ret += f'''
+ ret += f"""
<TR>
<TD WIDTH="150" valign="top" {color}><B>{f['periodText']}</B></TD>
<TD{color}>{f['forecastText']}</TD>
-</TR>'''
- ret += '</TABLE>'
+</TR>"""
+ ret += "</TABLE>"
return ret
def render_image(cameras: Dict[str, str]) -> str:
for camera in cameras:
- if camera['cameraId'] == 8063:
- return f'''
+ if camera["cameraId"] == 8063:
+ return f"""
<CENTER>
<A HREF='https://wsdot.com/travel/real-time/mountainpasses/Stevens'>
<IMG SRC={camera['cameraUrl']} WIDTH={camera['width'] * 1.75}>
</A>
<BR>
<I>{camera['cameraLabel']} ({camera['direction']})</I>
-</CENTER>'''
- return ''
+</CENTER>"""
+ return ""
def periodic_render(self, unused: str) -> bool:
page = requests.get(stevens_renderer.URL)
if page.status_code == 200:
contents = json.loads(page.content)
- mp = contents['mountainPass']
- conditions = contents['condition']
- cameras = contents['cameras']
- forecasts = contents['stationForecasts'][0]
- with file_writer.file_writer('stevens-conditions_5_3000.html') as f:
- f.write(f'''
+ mp = contents["mountainPass"]
+ conditions = contents["condition"]
+ cameras = contents["cameras"]
+ forecasts = contents["stationForecasts"][0]
+ with file_writer.file_writer("stevens-conditions_5_3000.html") as f:
+ f.write(
+ f"""
<H1>Stevens Pass Conditions:</H1>
<HR>
<TABLE WIDTH=90%>
{stevens_renderer.render_forecast(forecasts)}
</TD>
</TR>
-</TABLE>''')
+</TABLE>"""
+ )
return True
return False
+
# Test:
-#test = stevens_renderer({"Test", 123})
-#test.periodic_render("Test")
+# test = stevens_renderer({"Test", 123})
+# test.periodic_render("Test")