Compare commits

...

2 commits

2 changed files with 6 additions and 35 deletions

View file

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

View file

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