Add birthday email reminder functionality
Implements birthday reminder emails that are sent daily at 9 AM for birthdays occurring within the next 7 days. Integrates with existing birthday.py module and mail system to send notifications with appropriate timing-based subjects. Fixes #171 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
2203677146
commit
bcb3329fdd
65
update.py
65
update.py
|
|
@ -12,6 +12,7 @@ import deepdiff
|
|||
import flask
|
||||
import requests
|
||||
|
||||
import agenda.birthday
|
||||
import agenda.bristol_waste
|
||||
import agenda.fx
|
||||
import agenda.geomob
|
||||
|
|
@ -358,6 +359,66 @@ def update_gandi(config: flask.config.Config) -> None:
|
|||
out.write(r.text)
|
||||
|
||||
|
||||
def check_birthday_reminders(config: flask.config.Config) -> None:
|
||||
"""Check for upcoming birthdays and send email reminders."""
|
||||
today = date.today()
|
||||
data_dir = config["PERSONAL_DATA"]
|
||||
entities_file = os.path.join(data_dir, "entities.yaml")
|
||||
|
||||
if not os.path.exists(entities_file):
|
||||
return
|
||||
|
||||
# Get upcoming birthdays (next 7 days)
|
||||
birthdays = agenda.birthday.get_birthdays(today, entities_file)
|
||||
upcoming_birthdays = []
|
||||
|
||||
for birthday in birthdays:
|
||||
days_until = (birthday.date - today).days
|
||||
if 0 <= days_until <= 7:
|
||||
upcoming_birthdays.append((birthday, days_until))
|
||||
|
||||
if not upcoming_birthdays:
|
||||
return
|
||||
|
||||
# Group birthdays by days until
|
||||
birthday_groups = {}
|
||||
for birthday, days_until in upcoming_birthdays:
|
||||
if days_until not in birthday_groups:
|
||||
birthday_groups[days_until] = []
|
||||
birthday_groups[days_until].append(birthday)
|
||||
|
||||
# Send reminder emails
|
||||
for days_until, birthdays in birthday_groups.items():
|
||||
if days_until == 0:
|
||||
subject = "🎂 Birthday Today!"
|
||||
elif days_until == 1:
|
||||
subject = "🎂 Birthday Tomorrow!"
|
||||
else:
|
||||
subject = f"🎂 Birthday in {days_until} days"
|
||||
|
||||
body_lines = ["Birthday Reminder:\n"]
|
||||
for birthday in birthdays:
|
||||
date_str = birthday.date.strftime("%A, %B %d, %Y")
|
||||
if days_until == 0:
|
||||
body_lines.append(f"Today: {birthday.title} - {date_str}")
|
||||
elif days_until == 1:
|
||||
body_lines.append(f"Tomorrow: {birthday.title} - {date_str}")
|
||||
else:
|
||||
body_lines.append(f"{date_str}: {birthday.title}")
|
||||
|
||||
body_lines.append(
|
||||
f"\nView all birthdays: https://edwardbetts.com/agenda/birthdays"
|
||||
)
|
||||
|
||||
body = "\n".join(body_lines)
|
||||
|
||||
if sys.stdin.isatty():
|
||||
print(f"Birthday reminder: {subject}")
|
||||
print(body)
|
||||
|
||||
agenda.mail.send_mail(config, subject, body)
|
||||
|
||||
|
||||
def main() -> None:
|
||||
"""Update caches."""
|
||||
now = datetime.now()
|
||||
|
|
@ -376,6 +437,10 @@ def main() -> None:
|
|||
|
||||
update_thespacedevs(app.config)
|
||||
|
||||
# Check for birthday reminders daily at 9 AM
|
||||
if hour == 9:
|
||||
check_birthday_reminders(app.config)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
Loading…
Reference in a new issue