diff options
| author | Scott Gasch <[email protected]> | 2022-03-28 09:32:22 -0700 |
|---|---|---|
| committer | Scott Gasch <[email protected]> | 2022-03-28 09:32:22 -0700 |
| commit | 01762dc93591fda9cd179ee6faa32145790800b4 (patch) | |
| tree | 709df574ad21a6c38de1fa3bddcc1f788c683689 /cached | |
| parent | dab4a70ccc2ad9c4a708fc738f07ec8022b3d406 (diff) | |
Cleanup weather_data.py.
Diffstat (limited to 'cached')
| -rw-r--r-- | cached/weather_data.py | 20 |
1 files changed, 11 insertions, 9 deletions
diff --git a/cached/weather_data.py b/cached/weather_data.py index 29a1d54..8793bd3 100644 --- a/cached/weather_data.py +++ b/cached/weather_data.py @@ -11,7 +11,7 @@ import logging import os import urllib.request from dataclasses import dataclass -from typing import Any, List +from typing import Any, Dict, List, Optional from overrides import overrides @@ -20,6 +20,8 @@ import config import datetime_utils import list_utils import persistent +import scott_secrets +import type_utils logger = logging.getLogger(__name__) @@ -56,7 +58,7 @@ class WeatherData: @persistent.persistent_autoloaded_singleton() # type: ignore class CachedWeatherData(persistent.Persistent): - def __init__(self, weather_data=None): + def __init__(self, weather_data: Dict[datetime.date, WeatherData] = None): if weather_data is not None: self.weather_data = weather_data return @@ -80,12 +82,12 @@ class CachedWeatherData(persistent.Persistent): } now = datetime.datetime.now() dates = set() - highs = {} - lows = {} - conditions = {} - precip = {} + highs: Dict[datetime.date, Optional[float]] = {} + lows: Dict[datetime.date, Optional[float]] = {} + conditions: Dict[datetime.date, List[str]] = {} + precip: Dict[datetime.date, float] = {} param = "id=5786882" # Bellevue, WA - key = "c0b160c49743622f62a9cd3cda0270b3" + key = scott_secrets.OPEN_WEATHER_MAP_KEY www = urllib.request.urlopen( f'http://api.openweathermap.org/data/2.5/weather?zip=98005,us&APPID={key}&units=imperial' ) @@ -173,8 +175,8 @@ class CachedWeatherData(persistent.Persistent): icon = '🌙' self.weather_data[dt] = WeatherData( date=dt, - high=highs[dt], - low=lows[dt], + high=type_utils.unwrap_optional(highs[dt]), + low=type_utils.unwrap_optional(lows[dt]), precipitation_inches=precip[dt] / 25.4, conditions=conditions[dt], most_common_condition=most_common_condition, |
