#!/usr/bin/env python3
+# © Copyright 2021-2022, Scott Gasch
+
+"""How's the weather going to be tomorrow?"""
+
import datetime
import logging
import os
@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
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
-
- with open(config.config['weather_forecast_cachefile'], 'rb') as rf:
- weather_data = pickle.load(rf)
- return cls(weather_data)
- return None
+ def get_filename() -> str:
+ return config.config['weather_forecast_cachefile']
+ @staticmethod
@overrides
- def save(self) -> bool:
- import pickle
-
- with open(config.config['weather_forecast_cachefile'], 'wb') as wf:
- pickle.dump(
- self.forecasts,
- wf,
- pickle.HIGHEST_PROTOCOL,
- )
+ def should_we_save_data(filename: str) -> bool:
return True
+
+ @staticmethod
+ @overrides
+ 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(),
+ )
+
+ @overrides
+ def get_persistent_data(self) -> Any:
+ return self.forecasts