X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=cached%2Fweather_forecast.py;h=d1e754025eeaadeee84cfc12b38a1c53e8a547ee;hb=3f4818bf9d1f3071c4e2906896d422810b5776bc;hp=2509f4343b237cf331098a8a65003e1043144b95;hpb=ed47f1a0c31184280a303563237e34c0e53437d7;p=python_utils.git diff --git a/cached/weather_forecast.py b/cached/weather_forecast.py index 2509f43..d1e7540 100644 --- a/cached/weather_forecast.py +++ b/cached/weather_forecast.py @@ -4,11 +4,13 @@ from dataclasses import dataclass import datetime import logging import os +from typing import Any import urllib.request import astral # type: ignore from astral.sun import sun # type: ignore from bs4 import BeautifulSoup # type: ignore +from overrides import overrides import pytz import argparse_utils @@ -49,7 +51,7 @@ class WeatherForecast: @persistent.persistent_autoloaded_singleton() -class CachedDetailedWeatherForecast(object): +class CachedDetailedWeatherForecast(persistent.Persistent): def __init__(self, forecasts = None): if forecasts is not None: self.forecasts = forecasts @@ -129,7 +131,8 @@ class CachedDetailedWeatherForecast(object): ) @classmethod - def load(cls): + @overrides + def load(cls) -> Any: if persistent.was_file_written_within_n_seconds( config.config['weather_forecast_cachefile'], config.config['weather_forecast_stalest_acceptable'].total_seconds(), @@ -140,7 +143,8 @@ class CachedDetailedWeatherForecast(object): return cls(weather_data) return None - def save(self): + @overrides + def save(self) -> bool: import pickle with open(config.config['weather_forecast_cachefile'], 'wb') as wf: pickle.dump( @@ -148,3 +152,4 @@ class CachedDetailedWeatherForecast(object): wf, pickle.HIGHEST_PROTOCOL, ) + return True