Skip to content

Commit

Permalink
Implement Multi-month
Browse files Browse the repository at this point in the history
  • Loading branch information
PhongT16 committed Apr 17, 2024
1 parent e246fed commit 87571e1
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 13 deletions.
4 changes: 2 additions & 2 deletions GenerateReport.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
69 changes: 58 additions & 11 deletions OutlookCalendar.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand All @@ -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

Expand Down

0 comments on commit 87571e1

Please sign in to comment.