# HG changeset patch # User Matti Hamalainen # Date 1467704142 -10800 # Node ID 125c4cbca3adb3028d27e3aa2e647591434334c0 # Parent d58a0a1f23fadd9b8957f1763af7746f4a76dcf2 Event merging work. diff -r d58a0a1f23fa -r 125c4cbca3ad multimerge.py --- a/multimerge.py Tue Jul 05 10:34:58 2016 +0300 +++ b/multimerge.py Tue Jul 05 10:35:42 2016 +0300 @@ -411,16 +411,24 @@ ## Start merging events .. gcm_debug("Re-merging events to target calendar ..") -dst_gcm_ids = map(lambda x: x["gcm_id"], dst_events) -src_ids = map(lambda x: x["id"], src_events) -dst_ids = map(lambda x: x["id"], dst_events) -rm_ids = [x for x in dst_ids if x not in src_ids] +dst_gcm_ids = frozenset(map(lambda x: x["gcm_id"], dst_events)) +src_ids = frozenset(map(lambda x: x["id"], src_events)) +dst_ids = frozenset(map(lambda x: x["id"], dst_events)) for event in src_events: # Does the event exist already in the target? if event["gcm_id"] in dst_gcm_ids: - # Yes. Thus, we just update the event + ## Yes. Thus, we just update the event. + event["status"] = "confirmed" else: - ## Insert new event + ## Event does not seem to exist. Insert new event. + event.pop("iCalUID", None) # Remove the iCalUID, having it conflicts with event ID + event["id"] = event["gcm_id"] # Replace Google generated ID with our own + try: + new_event = service.events().insert(calendarId=cfg.dest_id, body=event).execute() + except Exception as e: + gcm_fatal("Failed to insert new event:\n{0}\n\nERROR: {1}\n".format(event, str(e))) + +## Remove "stale" events gcm_debug("Finished.")