#!/usr/bin/env python3 import json import logging import requests from typing import Dict import file_writer 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)} |