Add upcoming birthdays

Closes: #1
This commit is contained in:
Edward Betts 2023-10-07 08:18:52 +01:00
parent e6e113e14a
commit f18c725221

View file

@ -265,6 +265,37 @@ def get_us_holiday(input_date: date) -> dict[str, date | str]:
return {"date": next_hol[0], "title": next_hol[1]} return {"date": next_hol[0], "title": next_hol[1]}
def next_birthday(from_date: date, birth_date: date) -> dict[str, int | date]:
"""Calculate the date of the next birthday based on a given birth date."""
next_birthday_date = birth_date.replace(year=from_date.year)
if from_date > next_birthday_date:
next_birthday_date = birth_date.replace(year=from_date.year + 1)
age_at_next_birthday = next_birthday_date.year - birth_date.year
return {"next_birthday": next_birthday_date, "age": age_at_next_birthday}
def get_birthdays(
from_date: date, config: configparser.ConfigParser
) -> list[dict[str, date | str]]:
if "birthdays" not in config:
return []
events = []
for name, date_str in config["birthdays"].items():
bday = next_birthday(from_date, datetime.strptime(date_str, "%Y-%m-%d").date())
events.append(
{
"date": bday["next_birthday"],
"name": "birthday",
"title": f"{name} (aged {bday['age']})",
}
)
return events
def get_data(now: datetime) -> dict[str, str | object]: def get_data(now: datetime) -> dict[str, str | object]:
"""Get data to display on agenda dashboard.""" """Get data to display on agenda dashboard."""
rocket_dir = os.path.join(data_dir, "thespacedevs") rocket_dir = os.path.join(data_dir, "thespacedevs")
@ -305,6 +336,8 @@ def get_data(now: datetime) -> dict[str, str | object]:
for key, value in xmas_last_posting_dates.items(): for key, value in xmas_last_posting_dates.items():
events.append({"name": f"xmas_last_{key}", "date": value}) events.append({"name": f"xmas_last_{key}", "date": value})
events += get_birthdays(today, config)
next_up_series = { next_up_series = {
"date": date(2026, 6, 1), "date": date(2026, 6, 1),
"title": "70 Up", "title": "70 Up",