chiark / gitweb /
check event isn't already cancelled before deleting
authorMatthew Vernon <mv3@sanger.ac.uk>
Tue, 23 Oct 2018 15:39:39 +0000 (16:39 +0100)
committerMatthew Vernon <mv3@sanger.ac.uk>
Tue, 23 Oct 2018 15:39:39 +0000 (16:39 +0100)
gooswapper.py

index dbc4204..9f4cefa 100644 (file)
@@ -74,6 +74,9 @@ def get_ex_event_by_id_and_changekey(acct,itemid,changekey):
     l=list(acct.fetch([(itemid,changekey)]))
     return list(acct.fetch([(itemid,changekey)]))[0]
 
+def get_gcal_event_by_eventid(gcal_acct,eventId,gcal_id="primary"):
+    return gcal_acct.events().get(calendarId=gcal_id,eventId=eventId).execute()
+
 def get_gcal_recur_instance(gcal_acct,gcal_master,start,gcal_id="primary"):
     ans = gcal_acct.events().instances(calendarId=gcal_id,
                                        eventId=gcal_master,
@@ -289,9 +292,13 @@ def add_ex_to_gcal(ex_acct,
 def del_ex_to_gcal(ex_acct, gcal_acct, events, deleted, gcal_id="primary"):
     for ev_id in deleted:
         if events[ev_id].gcal_link is not None:
-            gcal_acct.events().delete(calendarId=gcal_id,
-                                      eventId=events[ev_id].gcal_link,
-                                      sendUpdates="none").execute()
+            gevent = get_gcal_event_by_eventid(gcal_acct,
+                                               events[ev_id].gcal_link,
+                                               gcal_id)
+            if gevent["status"] != "cancelled":
+                gcal_acct.events().delete(calendarId=gcal_id,
+                                          eventId=events[ev_id].gcal_link,
+                                          sendUpdates="none").execute()
 
 def update_ex_to_gcal(ex_acct,
                       gcal_acct,gcal_tz,