From 037981040af95dc2539b9b9f20b7f5c329a46a30 Mon Sep 17 00:00:00 2001 From: "Fredrick W. Warren" Date: Sun, 29 Dec 2024 07:20:53 -0700 Subject: [PATCH] moved processing into months and month --- main.py | 34 ++++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/main.py b/main.py index 9a22bca..2840ef9 100755 --- a/main.py +++ b/main.py @@ -121,30 +121,36 @@ def write_calendar(events: list[Event]) -> None: writer.write() -def process_year(MONTHS, monthly_events): - """process full year and return list of events""" + +def process_month(MONTHS, monthly_events, week_of_month, week, events): + """process one MONTHS of events""" + for day_of_week, day in enumerate(week): + if day > 0: + """ + month, week_of_month, day_of_week, day + use monthly_events[day_of_week] + """ + print(f" {day_of_week}-{day:02d}", end=" ") + day_events = [x[1:] for x in monthly_events[day_of_week] if week_of_month + 1 in x[0]] + print(day_events) + print() + return events + + +def process_months(MONTHS, monthly_events): + """process full year of MONTHS and return list of events""" events = [] for month in range(1, 13): print(f"MONTH: {month}") for week_of_month, week in enumerate(MONTHS[month]): print(week_of_month, week) - for day_of_week, day in enumerate(week): - if day > 0: - """ - month, week_of_month, day_of_week, day - use monthly_events[day_of_week] - """ - print(f" {day_of_week}-{day:02d}", end=" ") - day_events = [x[1:] for x in monthly_events[day_of_week] if week_of_month + 1 in x[0]] - print(day_events) - print() - + events = process_month(MONTHS, monthly_events, week_of_month, week, events) return events @click.command() def main(): """create csv file""" - events = process_year(MONTHS, monthly_events) + events = process_months(MONTHS, monthly_events) events = sort_events(events) write_calendar(events) sys.exit(0)