diff options
author | Aki <please@ignore.pl> | 2023-04-08 01:04:00 +0200 |
---|---|---|
committer | Aki <please@ignore.pl> | 2023-04-08 01:04:00 +0200 |
commit | d7e9b83def504b352b25bb1432a6621e720fb4cd (patch) | |
tree | 9ca3fdb77f08f9d819b4ff5f0f789c5baf41318c | |
parent | f51bfac6733e30739396eb89fe3ff15d8117058a (diff) | |
download | waterspout-radar-d7e9b83def504b352b25bb1432a6621e720fb4cd.zip waterspout-radar-d7e9b83def504b352b25bb1432a6621e720fb4cd.tar.gz waterspout-radar-d7e9b83def504b352b25bb1432a6621e720fb4cd.tar.bz2 |
Limit predictions to selected period or next days otherwise
-rw-r--r-- | waterspout_radar/_storage.py | 9 |
1 files changed, 8 insertions, 1 deletions
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: |