Skip to content

Commit

Permalink
Update snapshot generator: group holidays by subdiv (#1578)
Browse files Browse the repository at this point in the history
  • Loading branch information
KJhellico authored Nov 30, 2023
1 parent 59dde59 commit de9997f
Show file tree
Hide file tree
Showing 616 changed files with 639,546 additions and 45,493 deletions.
17 changes: 3 additions & 14 deletions scripts/generate_snapshots.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
sys.path.append(f"{Path.cwd()}") # Make holidays visible.

import holidays
from holidays import HOLIDAY_NAME_DELIMITER, list_supported_countries, list_supported_financial
from holidays import list_supported_countries, list_supported_financial


class SnapshotGenerator:
Expand Down Expand Up @@ -62,15 +62,6 @@ def save(snapshot, file_path):
)
output.write("\n") # Get along with pre-commit.

@staticmethod
def update_snapshot(snapshot, data):
for dt, name in data.items():
holiday_names = set(
snapshot[dt].split(HOLIDAY_NAME_DELIMITER) if dt in snapshot else ()
)
holiday_names.update(name.split(HOLIDAY_NAME_DELIMITER))
snapshot[dt] = HOLIDAY_NAME_DELIMITER.join(sorted(holiday_names))

def generate_country_snapshots(self):
"""Generates country snapshots."""
if len(self.args.market) > 0:
Expand All @@ -87,20 +78,18 @@ def generate_country_snapshots(self):

for country_code in country_list:
country = getattr(holidays, country_code)
snapshot = {}

for subdiv in (None,) + country.subdivisions:
self.update_snapshot(
snapshot,
self.save(
holidays.country_holidays(
country_code,
subdiv=subdiv,
years=self.years,
categories=country.supported_categories,
language="en_US",
),
f"snapshots/countries/{country_code}_{subdiv or 'COMMON'}.json",
)
self.save(snapshot, f"snapshots/countries/{country_code}.json")

def generate_financial_snapshots(self):
"""Generates financial snapshots."""
Expand Down
2,629 changes: 0 additions & 2,629 deletions snapshots/countries/AD.json

This file was deleted.

Loading

0 comments on commit de9997f

Please sign in to comment.