Mercurial > hg > gcmultimerge
changeset 34:125c4cbca3ad
Event merging work.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 05 Jul 2016 10:35:42 +0300 |
parents | d58a0a1f23fa |
children | be1e798cc60a |
files | multimerge.py |
diffstat | 1 files changed, 14 insertions(+), 6 deletions(-) [+] |
line wrap: on
line diff
--- 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.")