Compare commits

...

3 commits

Author SHA1 Message Date
Edward Betts aafd37ab5a Read birthdays from YAML
Closes: #22
2023-10-21 09:28:58 +01:00
Edward Betts 155181be18 Import dateutil.tz for tzlocal 2023-10-21 09:28:23 +01:00
Edward Betts acd95db18d Update gitignore 2023-10-21 09:27:40 +01:00
2 changed files with 12 additions and 6 deletions

1
.gitignore vendored
View file

@ -3,3 +3,4 @@ __pycache__/
__pycache__
.mypy_cache
config
.hypothesis/

View file

@ -11,6 +11,7 @@ from typing import List
import dateutil
import dateutil.parser
import dateutil.tz
import exchange_calendars
import holidays
import lxml
@ -304,16 +305,20 @@ def next_birthday(from_date: date, birth_date: date) -> tuple[date, int]:
def get_birthdays(from_date: date, config: configparser.ConfigParser) -> list[Event]:
"""Get birthdays from config."""
if "birthdays" not in config:
return []
filename = config["data"]["entities"]
events = []
for name, date_str in config["birthdays"].items():
bday = next_birthday(from_date, datetime.strptime(date_str, "%Y-%m-%d").date())
with open(filename) 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[0],
date=bday,
name="birthday",
title=f"{name.title()} (aged {bday[1]})",
title=f'{entity["label"]} (aged {age})',
)
)