From 2ecb916a2fb8711681d92ed005d1fcabc84493cd Mon Sep 17 00:00:00 2001 From: "Fredrick W. Warren" Date: Sun, 29 Dec 2024 10:20:36 -0700 Subject: [PATCH] pass filename to writer, default calendar.csv --- main.py | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 37ff5f6..6e843e4 100755 --- a/main.py +++ b/main.py @@ -119,9 +119,9 @@ def create_event(name: str, # events.append(event) -def write_calendar(events: list[Event]) -> None: +def write_calendar(events: list[Event], filename) -> None: """write calendar to csv file""" - with open("calendar.csv", "w", encoding="utf-8") as handle: + with open(filename, "w", encoding="utf-8") as handle: writer =DataclassWriter(handle, events, Event) writer.map("event_name").to("EVENT NAME") writer.map("venue_name").to("VENUE NAME") @@ -176,10 +176,12 @@ def process_months(months, monthly_events, year): events = process_month(months, monthly_events, year, month, week_of_month, week, events) return events +# @click.argument('filename', type=click.File('w'), default="calendar.csv", required=False) @click.command() @click.option("--debug", "-d", is_flag=True, default=False, help="Print debug output") @click.option('--year', "-y", type=int, default=date.today().year, help='Specify the year.') -def main(debug, year): +@click.argument('filename', default="calendar.csv", required=False) +def main(debug, year, filename): """create csv file""" global DEBUG DEBUG = debug @@ -187,7 +189,7 @@ def main(debug, year): monthly_events = initalize_events(EVENT_LIST) events = process_months(months, monthly_events, year) # events = sort_events(events) - write_calendar(events) + write_calendar(events, filename) sys.exit(0)