Skip to content

Commit

Permalink
Merge pull request #105 from wolterhv/implement_country_subdivisions
Browse files Browse the repository at this point in the history
Add support for country subdivisions.
  • Loading branch information
anufrievroman authored Aug 12, 2024
2 parents a6d4a2c + d0313f9 commit 8ebfd91
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion calcure/loaders.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,14 +173,23 @@ def load(self):

def load_country(self, country):
"""Load list of holidays from 'holidays' module"""

def get_country_and_subdivision(country):
"""Get country and subdivision, where encoded."""
if ":" in country:
return tuple(country.split(":"))
else:
return (country, None)

try:
import holidays as hl
from holidays import registry

(country, subdivision) = get_country_and_subdivision(country)
country_codes = {x[0]: x[2] for x in registry.COUNTRIES.values()}
country_code = country_codes.get(country)
year = datetime.date.today().year
holiday_events = (getattr(hl, country))(years=[year+x for x in range(-2, 5)])
holiday_events = (getattr(hl, country))(subdiv=subdivision, years=[year+x for x in range(-2, 5)])
for date, name in holiday_events.items():

# Convert to persian date if needed:
Expand Down

0 comments on commit 8ebfd91

Please sign in to comment.