From 40eac970421fe55402298c0451d5fb1f7ed431ff Mon Sep 17 00:00:00 2001 From: Dan Sahagian <45240763+dansahagian@users.noreply.github.com> Date: Thu, 26 Sep 2024 20:02:15 -0700 Subject: [PATCH] Fix reminders to only send a single email --- fbsurvivor/core/services.py | 6 +++++- fbsurvivor/core/utils/deadlines.py | 7 ++++++- fbsurvivor/core/utils/reminders.py | 25 ++++++++++++------------- 3 files changed, 23 insertions(+), 15 deletions(-) diff --git a/fbsurvivor/core/services.py b/fbsurvivor/core/services.py index 8f0963d..39156b6 100644 --- a/fbsurvivor/core/services.py +++ b/fbsurvivor/core/services.py @@ -29,9 +29,13 @@ def __init__(self, season: int | Season | None = None): else: self.season = None + @staticmethod + def get_current(): + return Season.objects.get(is_current=True) + @staticmethod def get_live(): - return Season.objects.filter(is_live=True) + return Season.objects.filter(is_live=True).order_by("year") def get_next_week(self): weeks = Week.objects.filter( diff --git a/fbsurvivor/core/utils/deadlines.py b/fbsurvivor/core/utils/deadlines.py index f64b228..3d26350 100644 --- a/fbsurvivor/core/utils/deadlines.py +++ b/fbsurvivor/core/utils/deadlines.py @@ -3,6 +3,7 @@ import arrow from fbsurvivor.core.models import Lock, Pick, PlayerStatus, Season, Week +from fbsurvivor.core.services import SeasonService def _zero_pad_number(number): @@ -111,6 +112,10 @@ def get_reminder_message(season: Season, next_week: Week) -> str | None: weekly_deadline = get_weekly_deadline(season, next_week) if weekly_deadline: - message += f"All Teams: {get_countdown(weekly_deadline)}" + message += f"All Teams: {get_countdown(weekly_deadline)}\n\n" + + if message: + live_seasons = "\n- ".join([x.description for x in SeasonService.get_live()]) + message += f"You are missing a pick in one of the following seasons:\n- {live_seasons}" return message if message else None diff --git a/fbsurvivor/core/utils/reminders.py b/fbsurvivor/core/utils/reminders.py index 1d76c98..4997a6a 100644 --- a/fbsurvivor/core/utils/reminders.py +++ b/fbsurvivor/core/utils/reminders.py @@ -5,21 +5,20 @@ def send_reminders(): - for season in SeasonService.get_live(): - season_service = SeasonService(season) + current_season = SeasonService.get_current() - next_week: Week = season_service.get_next_week() + season_service = SeasonService(current_season) - if not next_week: - return + next_week: Week = season_service.get_next_week() + if not next_week: + return - message = get_reminder_message(season, next_week) + message = get_reminder_message(current_season, next_week) + if not message: + return - if not message: - return + subject = f"Survivor {current_season.year}: Week {next_week.week_num} Reminder" + message = f"Week {next_week.week_num} Locks:\n\n" + message - subject = f"Survivor {season.description}: Week {next_week.week_num} Reminder" - message = f"Week {next_week.week_num} Locks:\n\n" + message - - if email_recipients := list(PlayerStatus.objects.for_email_reminders(next_week)): - send_email(subject, email_recipients, message) + if email_recipients := list(PlayerStatus.objects.for_email_reminders(next_week)): + send_email(subject, email_recipients, message)