Mercurial > hg > gcmultimerge
comparison multimerge.py @ 34:125c4cbca3ad
Event merging work.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 05 Jul 2016 10:35:42 +0300 |
parents | d58a0a1f23fa |
children | be1e798cc60a |
comparison
equal
deleted
inserted
replaced
33:d58a0a1f23fa | 34:125c4cbca3ad |
---|---|
409 gcm_debug(u"No current events.") | 409 gcm_debug(u"No current events.") |
410 | 410 |
411 | 411 |
412 ## Start merging events .. | 412 ## Start merging events .. |
413 gcm_debug("Re-merging events to target calendar ..") | 413 gcm_debug("Re-merging events to target calendar ..") |
414 dst_gcm_ids = map(lambda x: x["gcm_id"], dst_events) | 414 dst_gcm_ids = frozenset(map(lambda x: x["gcm_id"], dst_events)) |
415 src_ids = map(lambda x: x["id"], src_events) | 415 src_ids = frozenset(map(lambda x: x["id"], src_events)) |
416 dst_ids = map(lambda x: x["id"], dst_events) | 416 dst_ids = frozenset(map(lambda x: x["id"], dst_events)) |
417 rm_ids = [x for x in dst_ids if x not in src_ids] | |
418 | 417 |
419 for event in src_events: | 418 for event in src_events: |
420 # Does the event exist already in the target? | 419 # Does the event exist already in the target? |
421 if event["gcm_id"] in dst_gcm_ids: | 420 if event["gcm_id"] in dst_gcm_ids: |
422 # Yes. Thus, we just update the event | 421 ## Yes. Thus, we just update the event. |
422 event["status"] = "confirmed" | |
423 else: | 423 else: |
424 ## Insert new event | 424 ## Event does not seem to exist. Insert new event. |
425 event.pop("iCalUID", None) # Remove the iCalUID, having it conflicts with event ID | |
426 event["id"] = event["gcm_id"] # Replace Google generated ID with our own | |
427 try: | |
428 new_event = service.events().insert(calendarId=cfg.dest_id, body=event).execute() | |
429 except Exception as e: | |
430 gcm_fatal("Failed to insert new event:\n{0}\n\nERROR: {1}\n".format(event, str(e))) | |
431 | |
432 ## Remove "stale" events | |
425 | 433 |
426 gcm_debug("Finished.") | 434 gcm_debug("Finished.") |