From d7e9b83def504b352b25bb1432a6621e720fb4cd Mon Sep 17 00:00:00 2001 From: Aki Date: Sat, 8 Apr 2023 01:04:00 +0200 Subject: Limit predictions to selected period or next days otherwise --- waterspout_radar/_storage.py | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/waterspout_radar/_storage.py b/waterspout_radar/_storage.py index aa9f0b1..97d16fd 100644 --- a/waterspout_radar/_storage.py +++ b/waterspout_radar/_storage.py @@ -13,7 +13,14 @@ class Storage: self.db = tinydb.TinyDB(pathname, create_dirs=True) def show(self, period: Period=None): - return map(_radar.Prediction.from_json, self.db.all()) + if not period: + now = datetime.datetime.now() + period = (now, now + datetime.timedelta(days=5)) + + def _is_between(prediction): + return period[0] < prediction.time and period[1] > prediction.time + + return filter(_is_between, map(_radar.Prediction.from_json, self.db.all())) def extend(self, predictions: typing.Iterable[_radar.Prediction]): for prediction in predictions: -- cgit v1.1