Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for country subdivisions. #105

Merged
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prior to this line, country would be set to either something like UnitedKingdom or UnitedKingdom:England. After this line, country is redefined to UnitedKingdom and subdivision is defined as England.

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