Created
February 10, 2023 08:43
-
-
Save frederik-elwert/e940f89c55bcc53c43aa7758d013c745 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python3 | |
import sys | |
import argparse | |
import logging | |
import datetime | |
import csv | |
from pathlib import Path | |
from holidays.countries.germany import Germany | |
def generate_holidays(year): | |
for state in Germany.subdivisions: | |
logging.info(f'Generate holidays for {state}.') | |
state_holidays = Germany(years=year, subdiv=state).items() | |
outfile = Path(f'Feiertage_{year}_{state}.csv') | |
logging.debug(f'Saving to file {outfile}.') | |
with outfile.open('w', newline='') as csvfile: | |
writer = csv.writer(csvfile) | |
writer.writerow(['Datum', 'Feiertag']) | |
writer.writerows(state_holidays) | |
def main(): | |
# Parse commandline arguments | |
arg_parser = argparse.ArgumentParser() | |
arg_parser.add_argument('-v', '--verbose', action='store_true') | |
arg_parser.add_argument('-y', '--year', default=datetime.date.today().year) | |
args = arg_parser.parse_args() | |
# Set up logging | |
if args.verbose: | |
level = logging.DEBUG | |
else: | |
level = logging.ERROR | |
logging.basicConfig(level=level) | |
generate_holidays(args.year) | |
# Return exit value | |
return 0 | |
if __name__ == '__main__': | |
sys.exit(main()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment