X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;ds=inline;f=stevens_renderer.py;h=95a6d54c35d296339073f2cea938836eb92f0f96;hb=4ee891c0fc29a002291c7c88f8d8fb5d14c28f92;hp=ab904ce0b97dbdaf620fbb58bfd0a9471ba85387;hpb=4b1f3d8a8b278ca6d62f461ea80c8ea21080c301;p=kiosk.git diff --git a/stevens_renderer.py b/stevens_renderer.py index ab904ce..95a6d54 100644 --- a/stevens_renderer.py +++ b/stevens_renderer.py @@ -1,45 +1,132 @@ -import renderer +#!/usr/bin/env python3 + +import json +import logging +import requests +from typing import Dict + import file_writer -import httplib -import xml.etree.ElementTree as ET - -class stevens_pass_conditions_renderer(renderer.debuggable_abstaining_renderer): - def __init__(self, name_to_timeout_dict, feed_site, feed_uris): - super(stevens_pass_conditions_renderer, self).__init__( - name_to_timeout_dict, False) - self.feed_site = feed_site - self.feed_uris = feed_uris - - def debug_prefix(self): - return "stevens" - - def periodic_render(self, key): - f = file_writer.file_writer('stevens-conditions_1_none.html') - for uri in self.feed_uris: - self.conn = httplib.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("
\n%s\n' % text) - f.close() - return True - f.close() +import renderer + + +logger = logging.getLogger(__name__) + + +class stevens_renderer(renderer.abstaining_renderer): + 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""" +
Temp: | +{conditions['temperature']}°{conditions['temperatureUnit'][0]} | +
Weather: | +{conditions['weather']} | +
Roadway: | +{conditions['roadCondition']} | +
Restrictions: | +"""
+ count = 0
+ 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":
+ count += 1
+ if count == 2:
+ ret += f"""
+ {conditions['restrictionOne']['travelDirectionName']}:
+ {conditions['restrictionOne']['publicPage']} + {conditions['restrictionTwo']['travelDirectionName']}: + {conditions['restrictionTwo']['publicPage']}""" + elif count == 1: + msg = conditions["restrictionOne"].get("publicPage", "no restrictions") + if msg.lower() != "no restrictions": + ret += f""" + {conditions['restrictionOne']['travelDirectionName']}: + {conditions['restrictionOne']['publicPage']} """ + else: + ret += f""" + {conditions['restrictionTwo']['travelDirectionName']}: + {conditions['restrictionTwo']['publicPage']} """ + else: + ret += """None. """ + ret += " |
{f['periodText']} | +{f['forecastText']} | +
+ {stevens_renderer.render_conditions(mp, conditions)} + | ++ {stevens_renderer.render_image(cameras)} + | +
+ {stevens_renderer.render_forecast(forecasts)} + | +