Skip to content

Commit

Permalink
fix #17
Browse files Browse the repository at this point in the history
  • Loading branch information
pantherale0 committed Sep 6, 2023
1 parent 6d29e61 commit 32c8b7e
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions pyroostermoney/child/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# pylint: disable=too-many-instance-attributes
# pylint: disable=too-many-arguments
import logging
from datetime import datetime, date
from datetime import datetime, date, timedelta

from pyroostermoney.const import URLS, CHILD_MAX_TRANSACTION_COUNT, TRANSFER_BODY
from pyroostermoney.api import RoosterSession
Expand Down Expand Up @@ -108,12 +108,19 @@ async def get_active_allowance_period(self):
allowance_periods = await self._session.request_handler(
url=URLS.get("get_child_allowance_periods").format(user_id=self.user_id))
allowance_periods = allowance_periods["response"]
active_periods = [p for p in allowance_periods
if datetime.strptime(p["startDate"], "%Y-%m-%d").date() <=
date.today() <=
datetime.strptime(p["endDate"], "%Y-%m-%d").date()]
if len(active_periods) != 1:
raise LookupError("No allowance period found")
search_date = datetime.now()
while True:
active_periods = [p for p in allowance_periods
if datetime.strptime(p["startDate"], "%Y-%m-%d").date() <=
search_date.date() <=
datetime.strptime(p["endDate"], "%Y-%m-%d").date()]
if len(active_periods) != 1 and search_date.date() < date.today():
raise LookupError("No allowance period found")
# run again but minus 7 days to address https://github.com/pantherale0/pyroostermoney/issues/17
elif len(active_periods) != 1:
search_date = search_date - timedelta(days=7)
else:
break

active_periods = active_periods[0]
self.active_allowance_period_id = int(active_periods.get("allowancePeriodId"))
Expand Down

0 comments on commit 32c8b7e

Please sign in to comment.