parent
75d18aed2b
commit
b33da8485c
|
@ -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
|
||||
]
|
||||
|
||||
|
|
|
@ -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 = {
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Reference in a new issue