From 87571e1f7169c442be53be7e6e548cbf1ee37ef5 Mon Sep 17 00:00:00 2001 From: Phong Date: Wed, 17 Apr 2024 00:58:34 -0500 Subject: [PATCH] Implement Multi-month --- GenerateReport.py | 4 +-- OutlookCalendar.py | 69 ++++++++++++++++++++++++++++++++++++++-------- 2 files changed, 60 insertions(+), 13 deletions(-) diff --git a/GenerateReport.py b/GenerateReport.py index 8310f58..0df2d9b 100644 --- a/GenerateReport.py +++ b/GenerateReport.py @@ -27,8 +27,8 @@ def print_table(simple_events): line = line + "," print(line) -def generate_report_for_specified_group(group_name, start_date, end_date, access_token): - emails = utils.get_email_list_from_ldap(group_name) +def generate_report_for_specified_group(emails, start_date, end_date, access_token): + # emails = utils.get_email_list_from_ldap(group_name) calendars = IndividualCalendar.get_individual_calendars(start_date, end_date, emails, access_token) events = IndividualCalendar.process_individual_calendars(calendars, start_date, end_date) print_table(events) diff --git a/OutlookCalendar.py b/OutlookCalendar.py index 8fb8ce0..ee34d7d 100644 --- a/OutlookCalendar.py +++ b/OutlookCalendar.py @@ -70,7 +70,17 @@ def main(configs): start_date = dates[0] end_date = dates[1] access_token = utils.acquire_access_token(app, configs['scopes']) - GenerateReport.generate_report_for_specified_group(group_name, start_date, end_date, access_token) + current_date = start_date + emails = utils.get_email_list_from_ldap(group_name) + while (current_date + timedelta(14) <= end_date): + + temp_end_date = current_date + timedelta(14) + GenerateReport.generate_report_for_specified_group(emails, current_date, temp_end_date, access_token) + + current_date = temp_end_date + + if (current_date < end_date): + GenerateReport.generate_report_for_specified_group(emails, current_date, end_date, access_token) return @@ -95,20 +105,57 @@ def main(configs): access_token = utils.acquire_access_token(app, configs['scopes']) # Retrieve the individual calendar and process it - individual_calendars_events = [] grouping = 10 - for group in [group_members[i : i + grouping] for i in range(0, len(group_members), grouping)]: - individual_calendars = IndividualCalendar.get_individual_calendars(start_date, end_date, group, access_token) - individual_calendars_events.extend(IndividualCalendar.process_individual_calendars(individual_calendars, start_date, end_date)) + current_date = start_date + print(f"END_DATE: {end_date}") + while (current_date + timedelta(14) <= end_date): + + individual_calendars_events = [] + temp_end_date = current_date + timedelta(14) + print(f"CURRENT: {current_date}") + print(f"END: {temp_end_date}") + for group in [group_members[i : i + grouping] for i in range(0, len(group_members), grouping)]: + individual_calendars = IndividualCalendar.get_individual_calendars(current_date, temp_end_date, group, access_token) + individual_calendars_events.extend(IndividualCalendar.process_individual_calendars(individual_calendars, current_date, temp_end_date)) + + # Retrieve the shared calendar and process it + shared_calendar_id = SharedCalendar.get_shared_calendar_id(configs['shared_calendar_name'], access_token) + shared_calendar = SharedCalendar.get_shared_calendar(shared_calendar_id, current_date, temp_end_date, access_token) + shared_calendar_events, event_ids = SharedCalendar.process_shared_calendar(shared_calendar, group_members) + + # Update the shared calendar + SharedCalendar.update_shared_calendar(individual_calendars_events, shared_calendar_events, event_ids, shared_calendar_id, configs['category_name'], configs['category_color'], access_token) + + current_date = temp_end_date + print("-----------------------------------------------------------") + + print(f"CURRENT: {current_date}") + individual_calendars_events = [] + if (current_date < end_date): + for group in [group_members[i : i + grouping] for i in range(0, len(group_members), grouping)]: + individual_calendars = IndividualCalendar.get_individual_calendars(current_date, end_date, group, access_token) + individual_calendars_events.extend(IndividualCalendar.process_individual_calendars(individual_calendars, current_date, end_date)) + + # Retrieve the shared calendar and process it + shared_calendar_id = SharedCalendar.get_shared_calendar_id(configs['shared_calendar_name'], access_token) + shared_calendar = SharedCalendar.get_shared_calendar(shared_calendar_id, current_date, end_date, access_token) + shared_calendar_events, event_ids = SharedCalendar.process_shared_calendar(shared_calendar, group_members) + + # Update the shared calendar + SharedCalendar.update_shared_calendar(individual_calendars_events, shared_calendar_events, event_ids, shared_calendar_id, configs['category_name'], configs['category_color'], access_token) + + # for group in [group_members[i : i + grouping] for i in range(0, len(group_members), grouping)]: + # individual_calendars = IndividualCalendar.get_individual_calendars(start_date, end_date, group, access_token) + # individual_calendars_events.extend(IndividualCalendar.process_individual_calendars(individual_calendars, start_date, end_date)) - # Retrieve the shared calendar and process it - shared_calendar_id = SharedCalendar.get_shared_calendar_id(configs['shared_calendar_name'], access_token) - shared_calendar = SharedCalendar.get_shared_calendar(shared_calendar_id, start_date, end_date, access_token) - shared_calendar_events, event_ids = SharedCalendar.process_shared_calendar(shared_calendar, group_members) + # # Retrieve the shared calendar and process it + # shared_calendar_id = SharedCalendar.get_shared_calendar_id(configs['shared_calendar_name'], access_token) + # shared_calendar = SharedCalendar.get_shared_calendar(shared_calendar_id, start_date, end_date, access_token) + # shared_calendar_events, event_ids = SharedCalendar.process_shared_calendar(shared_calendar, group_members) - # Update the shared calendar - SharedCalendar.update_shared_calendar(individual_calendars_events, shared_calendar_events, event_ids, shared_calendar_id, configs['category_name'], configs['category_color'], access_token) + # # Update the shared calendar + # SharedCalendar.update_shared_calendar(individual_calendars_events, shared_calendar_events, event_ids, shared_calendar_id, configs['category_name'], configs['category_color'], access_token) if args.manual_update: break