Compare commits
3 commits
aceee6ac4d
...
aafd37ab5a
Author | SHA1 | Date | |
---|---|---|---|
Edward Betts | aafd37ab5a | ||
Edward Betts | 155181be18 | ||
Edward Betts | acd95db18d |
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -3,3 +3,4 @@ __pycache__/
|
||||||
__pycache__
|
__pycache__
|
||||||
.mypy_cache
|
.mypy_cache
|
||||||
config
|
config
|
||||||
|
.hypothesis/
|
||||||
|
|
|
@ -11,6 +11,7 @@ from typing import List
|
||||||
|
|
||||||
import dateutil
|
import dateutil
|
||||||
import dateutil.parser
|
import dateutil.parser
|
||||||
|
import dateutil.tz
|
||||||
import exchange_calendars
|
import exchange_calendars
|
||||||
import holidays
|
import holidays
|
||||||
import lxml
|
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]:
|
def get_birthdays(from_date: date, config: configparser.ConfigParser) -> list[Event]:
|
||||||
"""Get birthdays from config."""
|
"""Get birthdays from config."""
|
||||||
if "birthdays" not in config:
|
filename = config["data"]["entities"]
|
||||||
return []
|
|
||||||
events = []
|
events = []
|
||||||
for name, date_str in config["birthdays"].items():
|
with open(filename) as f:
|
||||||
bday = next_birthday(from_date, datetime.strptime(date_str, "%Y-%m-%d").date())
|
entities = yaml.safe_load(f)
|
||||||
|
|
||||||
|
for entity in entities:
|
||||||
|
birthday = date(**entity["birthday"])
|
||||||
|
bday, age = next_birthday(from_date, birthday)
|
||||||
events.append(
|
events.append(
|
||||||
Event(
|
Event(
|
||||||
date=bday[0],
|
date=bday,
|
||||||
name="birthday",
|
name="birthday",
|
||||||
title=f"{name.title()} (aged {bday[1]})",
|
title=f'{entity["label"]} (aged {age})',
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue