Compare commits

..

No commits in common. "e8bda4f9694da61f558c94da08fcee74714be870" and "c24a83f161a57f1231ef93a0685f1b62a33e22c1" have entirely different histories.

2 changed files with 35 additions and 6 deletions

View file

@ -23,7 +23,7 @@ from dateutil.relativedelta import FR, relativedelta
from agenda import thespacedevs
from . import birthday, calendar, fx, gwr, markets, sun, waste_schedule
from . import calendar, fx, gwr, markets, sun, waste_schedule
from .types import Event
warnings.simplefilter(action="ignore", category=FutureWarning)
@ -293,6 +293,38 @@ def get_conferences(filepath: str) -> List[Event]:
return events
def next_birthday(from_date: date, birth_date: date) -> tuple[date, int]:
"""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_date, age_at_next_birthday
def get_birthdays(from_date: date, filepath: str) -> list[Event]:
"""Get birthdays from config."""
events = []
with open(filepath) as f:
entities = yaml.safe_load(f)
for entity in entities:
birthday = date(**entity["birthday"])
bday, age = next_birthday(from_date, birthday)
events.append(
Event(
date=bday,
name="birthday",
title=f'{entity["label"]} (aged {age})',
)
)
return events
def get_accommodation(from_date: date, filepath: str) -> list[Event]:
"""Get birthdays from config."""
events = []
@ -400,8 +432,6 @@ def get_data(now: datetime) -> typing.Mapping[str, str | object]:
"""Get data to display on agenda dashboard."""
rocket_dir = os.path.join(data_dir, "thespacedevs")
today = now.date()
last_week = today - timedelta(weeks=1)
last_year = today - timedelta(days=365)
reply = {
"now": now,
@ -447,7 +477,7 @@ def get_data(now: datetime) -> typing.Mapping[str, str | object]:
events.append(Event(name=f"xmas_last_{key}", date=value))
my_data = config["data"]["personal-data"]
events += birthday.get_birthdays(last_year, os.path.join(my_data, "entities.yaml"))
events += get_birthdays(today, os.path.join(my_data, "entities.yaml"))
events += get_accommodation(today, os.path.join(my_data, "accommodation.yaml"))
events += get_all_travel_events(today)
events += get_conferences(os.path.join(my_data, "conferences.yaml"))
@ -463,7 +493,6 @@ def get_data(now: datetime) -> typing.Mapping[str, str | object]:
events.sort(key=operator.attrgetter("as_datetime"))
reply["events"] = events
reply["last_week"] = last_week
reply["fullcalendar_events"] = calendar.build_events(events)

View file

@ -113,7 +113,7 @@
<h3>Agenda</h3>
{% for event in events if event.as_date >= last_week %}
{% for event in events %}
<div class="row border border-1 {% if event.name in class_map %} {{ class_map[event.name]}}{% endif %}">
<div class="col-md-3">
{{event.as_date.strftime("%a, %d, %b")}}