summaryrefslogtreecommitdiff
path: root/cached/weather_data.py
diff options
context:
space:
mode:
authorScott Gasch <[email protected]>2022-05-28 19:29:08 -0700
committerScott Gasch <[email protected]>2022-05-28 19:29:08 -0700
commit1e858172519e9339e4720b8bf9b39b6d9801e305 (patch)
tree75306d5a4eb3a9b512646f0acc5c6174644348a6 /cached/weather_data.py
parent52ff365609d3f5a81cb79dc4464b19bd5860cfc0 (diff)
Tweak around docstring to make prettier sphinx autodocs.
Diffstat (limited to 'cached/weather_data.py')
-rw-r--r--cached/weather_data.py21
1 files changed, 21 insertions, 0 deletions
diff --git a/cached/weather_data.py b/cached/weather_data.py
index 8793bd3..87c3260 100644
--- a/cached/weather_data.py
+++ b/cached/weather_data.py
@@ -59,6 +59,13 @@ class WeatherData:
@persistent.persistent_autoloaded_singleton() # type: ignore
class CachedWeatherData(persistent.Persistent):
def __init__(self, weather_data: Dict[datetime.date, WeatherData] = None):
+ """C'tor. Do not pass a dict except for testing purposes.
+
+ The @persistent_autoloaded_singleton decorator handles
+ invoking our load and save methods at construction time for
+ you.
+ """
+
if weather_data is not None:
self.weather_data = weather_data
return
@@ -186,6 +193,15 @@ class CachedWeatherData(persistent.Persistent):
@classmethod
@overrides
def load(cls) -> Any:
+
+ """Depending on whether we have fresh data persisted either uses that
+ data to instantiate the class or makes an HTTP request to fetch the
+ necessary data.
+
+ Note that because this is a subclass of Persistent this is taken
+ care of automatically.
+ """
+
if persistent.was_file_written_within_n_seconds(
config.config['weather_data_cachefile'],
config.config['weather_data_stalest_acceptable'].total_seconds(),
@@ -199,6 +215,11 @@ class CachedWeatherData(persistent.Persistent):
@overrides
def save(self) -> bool:
+ """
+ Saves the current data to disk if required. Again, because this is
+ a subclass of Persistent this is taken care of for you.
+ """
+
import pickle
with open(config.config['weather_data_cachefile'], 'wb') as wf: