From a9075a10e35fa32518851b217bd140794410170e Mon Sep 17 00:00:00 2001 From: David Barnett Date: Wed, 18 Sep 2024 08:13:53 -0600 Subject: [PATCH] Better output from `import` explaining what changes were made --- gcalcli/gcal.py | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/gcalcli/gcal.py b/gcalcli/gcal.py index 0ee68ee..e2303cf 100644 --- a/gcalcli/gcal.py +++ b/gcalcli/gcal.py @@ -1579,6 +1579,8 @@ def ImportICS(self, verbose=False, dump=False, reminders=None, '--use-legacy-import to restore the old behavior.\n\n') time.sleep(1) + cal = self.cals[0] + imported_cnt = 0 for event in events_to_import: if not event: continue @@ -1609,11 +1611,11 @@ def ImportICS(self, verbose=False, dump=False, reminders=None, # Import event import_method = ( self.get_events().import_ if ( - self._event_should_use_new_import_api(event, self.cals[0])) + self._event_should_use_new_import_api(event, cal)) else self.get_events().insert) try: new_event = self._retry_with_backoff( - import_method(calendarId=self.cals[0]['id'], body=event)) + import_method(calendarId=cal['id'], body=event)) except HttpError as e: try: is_skipped_dupe = any(detail.get('reason') == 'duplicate' @@ -1635,8 +1637,12 @@ def ImportICS(self, verbose=False, dump=False, reminders=None, self.printer.msg(f'Event details: {event}\n') self.printer.debug_msg(f'Error details: {e}\n') else: + imported_cnt += 1 hlink = new_event.get('htmlLink') self.printer.msg(f'New event added: {hlink}\n', 'green') - # TODO: return the number of events added + self.printer.msg( + f"Added {imported_cnt} events to calendar {cal['id']}\n" + ) + return True