import datetime import typing import tinydb from . import _radar Period = typing.Tuple[datetime.datetime, datetime.datetime] class Storage: def __init__(self, pathname): self.db = tinydb.TinyDB(pathname, create_dirs=True) def show(self, period: Period=None): return map(_radar.Prediction.from_json, self.db.all()) def extend(self, predictions: typing.Iterable[_radar.Prediction]): for prediction in predictions: self.db.insert(prediction.json()) def __iter__(self): return self.show()