Include local names on holiday list

Closes: #106
This commit is contained in:
Edward Betts 2024-01-16 16:22:04 +00:00
parent 75d18aed2b
commit b33da8485c
3 changed files with 22 additions and 3 deletions

View file

@ -60,15 +60,24 @@ def get_nyse_holidays(
def get_holidays(country: str, start_date: date, end_date: date) -> list[Holiday]:
"""Get holidays."""
found: list[Holiday] = []
uc_country = country.upper()
holiday_country = getattr(holidays, uc_country)
default_language = holiday_country.default_language
for year in range(start_date.year, end_date.year + 1):
hols = holidays.country_holidays(country.upper(), years=year, language="en_US")
en_hols = holidays.country_holidays(uc_country, years=year, language="en_US")
local_lang = holidays.country_holidays(
uc_country, years=year, language=default_language
)
found += [
Holiday(
date=hol_date,
name=title,
local_name=local_lang[hol_date],
country=country.lower(),
)
for hol_date, title in hols.items()
for hol_date, title in en_hols.items()
if start_date < hol_date < end_date
]

View file

@ -91,6 +91,16 @@ class Holiday:
name: str
country: str
date: datetime.date
local_name: str | None = None
@property
def display_name(self) -> str:
"""Format name for display."""
return (
f"{self.name} ({self.local_name})"
if self.local_name and self.local_name != self.name
else self.name
)
emojis = {

View file

@ -14,7 +14,7 @@
<td></td>
{% endif %}
<td>{{ country.flag }} {{ country.name }}</td>
<td>{{ item.name }}</td>
<td>{{ item.display_name }}</td>
</tr>
{% endfor %}
</table>