diff --git a/gcalcli/gcal.py b/gcalcli/gcal.py index 09a3c42..043a8e8 100644 --- a/gcalcli/gcal.py +++ b/gcalcli/gcal.py @@ -1464,32 +1464,36 @@ def ImportICS(self, verbose=False, dump=False, reminders=None, continue self._add_reminders(event, reminders) + if not verbose: - new_event = self._retry_with_backoff( - self.get_events().insert( - calendarId=self.cals[0]['id'], body=event - ) - ) - hlink = new_event.get('htmlLink') - self.printer.msg('New event added: %s\n' % hlink, 'green') - continue + # Don't prompt, just assume user wants to import. + pass + else: + # Prompt for whether to import. + self.printer.msg('\n[S]kip [i]mport [q]uit: ', 'magenta') + val = input() + if not val or val.lower() == 's': + continue + elif val.lower() == 'q': + sys.exit(0) + elif val.lower() == 'i': + # Import requested, continue + pass + else: + self.printer.err_msg('Error: invalid input\n') + sys.exit(1) - self.printer.msg('\n[S]kip [i]mport [q]uit: ', 'magenta') - val = input() - if not val or val.lower() == 's': - continue - if val.lower() == 'i': - new_event = self._retry_with_backoff( - self.get_events().insert( - calendarId=self.cals[0]['id'], body=event - ) + # Import event + import_method = ( + self.get_events().import_ if 'iCalUID' in event + else self.get_events().insert) + new_event = self._retry_with_backoff( + import_method( + calendarId=self.cals[0]['id'], body=event ) - hlink = new_event.get('htmlLink') - self.printer.msg('New event added: %s\n' % hlink, 'green') - elif val.lower() == 'q': - sys.exit(0) - else: - self.printer.err_msg('Error: invalid input\n') - sys.exit(1) + ) + hlink = new_event.get('htmlLink') + self.printer.msg(f'New event added: {hlink}\n', 'green') + # TODO: return the number of events added return True diff --git a/gcalcli/ics.py b/gcalcli/ics.py index 413f0ad..755e4ef 100644 --- a/gcalcli/ics.py +++ b/gcalcli/ics.py @@ -134,4 +134,10 @@ def CreateEventFromVOBJ( {'displayName': attendee.name, 'email': email} ) + if hasattr(ve, 'uid'): + uid = ve.uid.value.strip() + if verbose: + print(f'UID..........{uid}') + event['iCalUID'] = uid + return event