pollen: Improve (?) date handling
This commit is contained in:
parent
bf077a5af0
commit
2516b8d56c
@ -46,7 +46,7 @@ class PollenModule(BaseModule):
|
|||||||
_subcommand_table = {}
|
_subcommand_table = {}
|
||||||
|
|
||||||
_pollen_data = {} # PLZ -> Date -> Type -> Severity
|
_pollen_data = {} # PLZ -> Date -> Type -> Severity
|
||||||
_dates_notified = {} # JID -> [Dates already sent out]
|
_oldest_date_notified = {} # JID -> Oldest date sent out
|
||||||
_sleep_duration = 100
|
_sleep_duration = 100
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
@ -74,7 +74,7 @@ class PollenModule(BaseModule):
|
|||||||
# NOTE: Since we request the pollen_data at start anyway, we won't
|
# NOTE: Since we request the pollen_data at start anyway, we won't
|
||||||
# need to save it. We only save dates_notified to prevent
|
# need to save it. We only save dates_notified to prevent
|
||||||
# sending one notification too many.
|
# sending one notification too many.
|
||||||
self._dates_notified = self._stm.get_data("dates_notified")
|
self._oldest_date_notified = self._stm.get_data("oldest_date_notified")
|
||||||
|
|
||||||
loop = asyncio.get_event_loop()
|
loop = asyncio.get_event_loop()
|
||||||
periodic = loop.create_task(self._request_pollen_data(True))
|
periodic = loop.create_task(self._request_pollen_data(True))
|
||||||
@ -104,24 +104,20 @@ class PollenModule(BaseModule):
|
|||||||
Returns True, when the pollen data for the date of date has
|
Returns True, when the pollen data for the date of date has
|
||||||
already been sent to jid.
|
already been sent to jid.
|
||||||
"""
|
"""
|
||||||
if not jid in self._dates_notified:
|
if not jid in self._oldest_date_notified:
|
||||||
return False
|
return False
|
||||||
|
|
||||||
return date in self._dates_notified[jid]
|
return int(date.replace("-", "")) <= self._oldest_date_notified[jid]
|
||||||
|
|
||||||
def _set_dates_notified(self, jid, new_dates):
|
def _set_dates_notified(self, jid, new_dates):
|
||||||
"""
|
"""
|
||||||
Marks a date as being sent to a user. Also ensures that
|
Marks a date as being sent to a user. Also ensures that
|
||||||
there are at maximum 7 days in this list
|
there are at maximum 7 days in this list
|
||||||
"""
|
"""
|
||||||
if not jid in self._dates_notified:
|
date_ints = [int(date.replace("-", "") for date in new_dates)]
|
||||||
self._dates_notified[jid] = new_dates
|
oldest_date = max(date_ints)
|
||||||
self._stm.set_data("dates_notified", self._dates_notified)
|
self._oldest_date_notified[jid] = oldest_date
|
||||||
return
|
self._stm.set_data("oldest_date_notified", self._oldest_date_notified)
|
||||||
|
|
||||||
self._dates_notified[jid] += new_dates
|
|
||||||
self._dates_notified[jid] = self._dates_notified[jid][-7:]
|
|
||||||
self._stm.set_data("dates_notified", self._dates_notified)
|
|
||||||
|
|
||||||
def _broadcast_jid(self, jid, filter_allergies=[]):
|
def _broadcast_jid(self, jid, filter_allergies=[]):
|
||||||
"""
|
"""
|
||||||
|
Loading…
Reference in New Issue
Block a user