Skip to content

Commit

Permalink
Fix reminders to only send a single email
Browse files Browse the repository at this point in the history
  • Loading branch information
dansahagian committed Sep 27, 2024
1 parent 7a59087 commit 40eac97
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
6 changes: 5 additions & 1 deletion fbsurvivor/core/services.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
7 changes: 6 additions & 1 deletion fbsurvivor/core/utils/deadlines.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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
25 changes: 12 additions & 13 deletions fbsurvivor/core/utils/reminders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

0 comments on commit 40eac97

Please sign in to comment.