# HG changeset patch # User Matti Hamalainen # Date 1468313065 -10800 # Node ID b3f8621f1a25c6ea3df345166888e8e63a118265 # Parent 1ab40033bb874b59606ff447663050f7775fa02c Change how the target calendar settings work a bit. Also implement display of latest update timestamp in the target calendar name. diff -r 1ab40033bb87 -r b3f8621f1a25 multimerge.py --- a/multimerge.py Tue Jul 12 11:19:38 2016 +0300 +++ b/multimerge.py Tue Jul 12 11:44:25 2016 +0300 @@ -13,7 +13,7 @@ import re import codecs import math -#import time +import time #import datetime import smtplib @@ -345,7 +345,8 @@ cfg.mdef("source_regmap", False, cfg.is_list, cfg.trans_list, [1, 2]) cfg.mdef("source_regmap_len", False, None, None, len(cfg.source_regmap)) -cfg.mdef("dest_name", True, cfg.is_string, None, u"Raahen kansainvälisyystoiminta") +cfg.mdef("dest_name", True, cfg.is_string, None, u"Raahen kansainvälisyystoiminta [{0}]") +cfg.mdef("dest_regex", True, cfg.is_string, None, u"^Raahen kansainvälisyystoiminta") cfg.mdef("dest_id", True, cfg.is_string, None, None) cfg.mdef("noauth_local_webserver", False, None, None, True) @@ -406,13 +407,10 @@ gcm_fatal(u"Invalid source_regmap: {0}".format(str(e))) -if not cfg.dest_name and not cfg.dest_id: +if not cfg.dest_regex and not cfg.dest_id: gcm_fatal(u"Target calendar ID or name required, but not set.") -if cfg.dest_name: - cfg.mset("dest_name", cfg.mget("dest_name").strip()) - ## Initialize and authorize API connection credentials = gcm_get_credentials(cfg) @@ -445,12 +443,13 @@ ## Filter desired SOURCE calendars based on specified regexp src_re = re.compile(cfg.source_regex, re.UNICODE) +dst_re = re.compile(cfg.dest_regex, re.UNICODE) src_calendars = [] dst_calendar = None for calendar in calendars: if u"summary" in calendar: # Find destination calendar ID if not set - if not cfg.dest_id and cfg.dest_name == calendar["summary"].strip(): + if not cfg.dest_id and dst_re.match(calendar["summary"]): cfg.mset("dest_id", calendar["id"]) dst_calendar = calendar @@ -575,5 +574,16 @@ except Exception as e: gcm_fatal(u"Failed to delete stale event:\n{0}\n\nERROR: {1}\n".format(event, str(e))) +## Update the target calendar name with timestamp +t_time = time.localtime() +t_str = time.strftime("%d.%m.%Y %H:%M", t_time) +gcm_debug(u"Updating target calendar name timestamp {0}".format(t_str)) + +try: + dst_calendar["summary"] = cfg.dest_name.format(t_str) + new_calendar = service.calendars().update(calendarId=cfg.dest_id, body=dst_calendar).execute() +except Exception as e: + gcm_fatal(u"Failed to update target calendar:\n{0}\n\nERROR: {1}\n".format(dst_calendar, str(e))) + gcm_debug(u"Finished.")