-
-
Notifications
You must be signed in to change notification settings - Fork 608
Description
Is your feature request related to a problem? Please describe.
It can be unintuitive and repetitive to manually write Python scripts for generating holiday calendar exports per country when using the holidays library. While the library provides excellent data coverage, users who want to create localized .ics calendar files (e.g., for all supported categories in multiple languages and year ranges) must currently craft individual scripts for each country. This makes it harder to automate or reproduce results consistently across regions.
Describe the solution you'd like
Implement a single generic script that accepts a country code as a command-line argument. The logic would dynamically check for supported_categories for that country and generate the corresponding .ics files.
If the user runs the script without an argument, it will print the specific error message showing an example (e.g., python3 examples/vacanza.py IN).
Implement a year argument instead of hardcoding a range. For example: python vacanza-sholidays.py US 2025
It would also be useful to include an option to list only public holidays to exclude de-facto holidays. For example:
python vacanza-holidays.py US 2025 public-holidays
python vacanza-holidays.py US 2020-2025
We will then place this script in examples/vacanza.py and include the documentation/usage in both docs/examples.md and README.md.
Describe alternatives you've considered
- Writing ad-hoc scripts manually for each desired country.
- Reviewing source code and documentation to reproduce the export logic for individual locales.
- Using a generalized generator script with dynamic input (though this requires deeper familiarity with the API than average users have).
Additional context
Including Python recipes per country would clarify how to use advanced features (such as categories, language support, and ICalExporter) efficiently. It would also create a consistent, educational reference area within the examples/ folder of the repository, helping both newcomers and automation-focused developers.
Example of a python recipe for sweden.py that may be reused (thanks KJhellico):
from holidays.countries.sweden import SE
from holidays.ical import ICalExporter
def generate():
language = "sv"
years = range(2021, 2031)
for category in SE.supported_categories:
holidays = SE(include_sundays=False, years=years, categories=category, language=language)
file_path = f"SE_COMMON_{language.upper()}_{category.upper()}.ics"
ICalExporter(holidays).save_ics(file_path)
if __name__ == "__main__":
generate()