summaryrefslogtreecommitdiff
path: root/cached/weather_forecast.py
diff options
context:
space:
mode:
Diffstat (limited to 'cached/weather_forecast.py')
-rw-r--r--cached/weather_forecast.py38
1 files changed, 17 insertions, 21 deletions
diff --git a/cached/weather_forecast.py b/cached/weather_forecast.py
index b8a20ed..7973bbb 100644
--- a/cached/weather_forecast.py
+++ b/cached/weather_forecast.py
@@ -56,7 +56,7 @@ class WeatherForecast:
@persistent.persistent_autoloaded_singleton() # type: ignore
-class CachedDetailedWeatherForecast(persistent.Persistent):
+class CachedDetailedWeatherForecast(persistent.PicklingFileBasedPersistent):
def __init__(self, forecasts=None):
if forecasts is not None:
self.forecasts = forecasts
@@ -119,28 +119,24 @@ class CachedDetailedWeatherForecast(persistent.Persistent):
description=blurb,
)
- @classmethod
+ @staticmethod
@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(),
- ):
- import pickle
+ def get_filename() -> str:
+ return config.config['weather_forecast_cachefile']
- with open(config.config['weather_forecast_cachefile'], 'rb') as rf:
- weather_data = pickle.load(rf)
- return cls(weather_data)
- return None
+ @staticmethod
+ @overrides
+ def should_we_save_data(filename: str) -> bool:
+ return True
+ @staticmethod
@overrides
- def save(self) -> bool:
- import pickle
+ def should_we_load_data(filename: str) -> bool:
+ return persistent.was_file_written_within_n_seconds(
+ filename,
+ config.config['weather_forecast_stalest_acceptable'].total_seconds(),
+ )
- with open(config.config['weather_forecast_cachefile'], 'wb') as wf:
- pickle.dump(
- self.forecasts,
- wf,
- pickle.HIGHEST_PROTOCOL,
- )
- return True
+ @overrides
+ def get_persistent_data(self) -> Any:
+ return self.forecasts