From: Matthew Vernon Date: Wed, 24 Oct 2018 10:24:19 +0000 (+0100) Subject: When matching, add google events where we have unmatched exchange ones X-Git-Tag: v0.1~5 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~matthewv/git?a=commitdiff_plain;h=7107c588e854808e5671c72e50f6cb3f9dfbc568;p=gooswapper When matching, add google events where we have unmatched exchange ones 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. --- diff --git a/gooswapper.py b/gooswapper.py index ffad0e0..fba0c19 100644 --- a/gooswapper.py +++ b/gooswapper.py @@ -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 + toadd = [] 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 + missing=True 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 + missing = False 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)) + return toadd 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: - 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)