diff options
Diffstat (limited to 'waterspout_radar/_storage.py')
-rw-r--r-- | waterspout_radar/_storage.py | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/waterspout_radar/_storage.py b/waterspout_radar/_storage.py index 6b9b968..aa9f0b1 100644 --- a/waterspout_radar/_storage.py +++ b/waterspout_radar/_storage.py @@ -1,6 +1,8 @@ import datetime import typing +import tinydb + from . import _radar Period = typing.Tuple[datetime.datetime, datetime.datetime] @@ -8,11 +10,14 @@ Period = typing.Tuple[datetime.datetime, datetime.datetime] class Storage: def __init__(self, pathname): - pass + self.db = tinydb.TinyDB(pathname, create_dirs=True) def show(self, period: Period=None): - return [] + return map(_radar.Prediction.from_json, self.db.all()) def extend(self, predictions: typing.Iterable[_radar.Prediction]): for prediction in predictions: - print(prediction.time, prediction.swi) + self.db.insert(prediction.json()) + + def __iter__(self): + return self.show() |