chiark / gitweb /
When matching, add google events where we have unmatched exchange ones
authorMatthew Vernon <mv3@sanger.ac.uk>
Wed, 24 Oct 2018 10:24:19 +0000 (11:24 +0100)
committerMatthew Vernon <mv3@sanger.ac.uk>
Wed, 24 Oct 2018 10:24:19 +0000 (11:24 +0100)
i.e. if you have an event in Exchange where a matching google event
isn't found by matching, then create that event in google.

gooswapper.py

index ffad0e0bbf82a697dcf573d0a0cb7ecaf0bd4c21..fba0c19e473cd991d5ed3c0fef4ea7c573c4c294 100644 (file)
@@ -329,15 +329,13 @@ def match_ex_to_gcal(ex_acct,gcal_acct,gcal_tz,events,gcal_id="primary",ignore_l
     recur = 0
     matched = 0
     skipped = 0
     recur = 0
     matched = 0
     skipped = 0
+    toadd = []
     for ev_id in events:
         event = get_ex_event_by_itemid(ex_acct.calendar,ev_id)
     for ev_id in events:
         event = get_ex_event_by_itemid(ex_acct.calendar,ev_id)
-#        if event.is_recurring:
-#            recur += 1
-#            continue
-#next line needs to be elif if above uncommented
         if event.gcal_link is not None and ignore_link is False:
             skipped += 1
             continue
         if event.gcal_link is not None and ignore_link is False:
             skipped += 1
             continue
+        missing=True
         matches = gcal_acct.events().list(calendarId=gcal_id,
                                           timeMin=event.start.isoformat(),
                                           timeMax=event.end.isoformat()).execute()
         matches = gcal_acct.events().list(calendarId=gcal_id,
                                           timeMin=event.start.isoformat(),
                                           timeMax=event.end.isoformat()).execute()
@@ -364,8 +362,12 @@ def match_ex_to_gcal(ex_acct,gcal_acct,gcal_tz,events,gcal_id="primary",ignore_l
                     if err.resp.status == 403:
                         pass
                 matched += 1
                     if err.resp.status == 403:
                         pass
                 matched += 1
+                missing = False
                 break
                 break
+        if missing == True:
+            toadd.append(ev_id)
     logger.info("Matched %d events, skipped %d with existing link, and %d recurring ones" % (matched,skipped,recur))
     logger.info("Matched %d events, skipped %d with existing link, and %d recurring ones" % (matched,skipped,recur))
+    return toadd
     
 def get_gcal_cred():
     #each such file can only store a single credential
     
 def get_gcal_cred():
     #each such file can only store a single credential
@@ -412,7 +414,8 @@ def main():
         del_ex_to_gcal(ex_account,gcal_account,cache,deleted)
         update_ex_to_gcal(ex_account,gcal_account,gcal_tz,current,changed)
     else:
         del_ex_to_gcal(ex_account,gcal_account,cache,deleted)
         update_ex_to_gcal(ex_account,gcal_account,gcal_tz,current,changed)
     else:
-        match_ex_to_gcal(ex_account,gcal_account,gcal_tz,current)
+        toadd = match_ex_to_gcal(ex_account,gcal_account,gcal_tz,current)
+        add_ex_to_gcal(ex_account,gcal_account,gcal_tz,current,toadd)
         
     with open(cachepath,"wb") as f:
         pickle.dump(current,f)
         
     with open(cachepath,"wb") as f:
         pickle.dump(current,f)