From 0b97ad1e492fd0c3301bdb8805327e05ce5b77bd Mon Sep 17 00:00:00 2001 From: "Fredrick W. Warren" Date: Sun, 29 Dec 2024 08:23:16 -0700 Subject: [PATCH] added actuall event creation --- main.py | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/main.py b/main.py index 1a64a29..5c4f23b 100755 --- a/main.py +++ b/main.py @@ -85,8 +85,8 @@ def sort_events(events: list[Event]) -> list[Event]: events = sorted(events, key=lambda k: (k.start_date, k.start_time)) return events -def add_event(events: list[Event], - name: str, +def create_event(name: str, + location: str, categories: str, description: str, start, @@ -94,7 +94,7 @@ def add_event(events: list[Event], """create event""" # pylint: disable=too-many-arguments event = Event(name, - "Main Campus", + location, "", start.strftime("%Y-%m-%d"), start.strftime("%I:%M %p"), @@ -108,7 +108,8 @@ def add_event(events: list[Event], "", "", description) - events.append(event) + return event + # events.append(event) def write_calendar(events: list[Event]) -> None: @@ -133,13 +134,17 @@ def write_calendar(events: list[Event]) -> None: writer.write() -def process_day(events, day_events): +def process_day(events, year, month, day, day_events): """process all events for one day""" for event_item in day_events: - debug_print(f" {event_item}", DEBUG) + start = datetime(year, month, day, event_item[0], event_item[1]) + finish = datetime(year, month, day, event_item[2], event_item[3]) + debug_print(f" {start:%H:%M}-{finish:%H:%M} {event_item[6]:25} {event_item[4]:11} {event_item[5]:16} {event_item[7]:70.70}", DEBUG) + event = create_event(event_item[6], event_item[4], event_item[5], event_item[7], start, finish) + events.append(event) return events -def process_month(MONTHS, monthly_events, week_of_month, week, events): +def process_month(MONTHS, monthly_events, year, month, week_of_month, week, events): """process one MONTHS of events""" for day_of_week, day in enumerate(week): if day > 0: @@ -149,26 +154,25 @@ def process_month(MONTHS, monthly_events, week_of_month, week, events): """ debug_print(f" {day_of_week}-{day:02d}", DEBUG) day_events = [x[1:] for x in monthly_events[day_of_week] if week_of_month + 1 in x[0]] - # debug_print(day_events, DEBUG) - events = process_day(events, day_events) + events = process_day(events, year, month, day, day_events) debug_print("", DEBUG) return events -def process_months(MONTHS, monthly_events): +def process_months(MONTHS, monthly_events, year): """process full year of MONTHS and return list of events""" events = [] for month in range(1, 13): debug_print(f"MONTH: {month}", DEBUG) for week_of_month, week in enumerate(MONTHS[month]): debug_print(f"{week_of_month} {week}", DEBUG) - events = process_month(MONTHS, monthly_events, week_of_month, week, events) + events = process_month(MONTHS, monthly_events, year, month, week_of_month, week, events) return events @click.command() def main(): """create csv file""" - events = process_months(MONTHS, monthly_events) + events = process_months(MONTHS, monthly_events, YEAR) events = sort_events(events) write_calendar(events) sys.exit(0)