def update(self, other, that=None, this=None, sid=None): task, todo = ThisFromThat.update(self, other, that, this, sid) tdsync = self._engine tdapi = self._engine.client oxsync = self._other ox = self._other._ox update = self._update # region Toodledo task attributes # id, title, note, modified, completed, added # folder, context, goal, location, tag, # startdate, duedate, duedatemod, starttime, duetime, # remind, repeat, # status, star, priority, # length, timer # parent, children, order, # meta, previous, attachment, # shared, addedby, via, attachments # endregion # region Open-Xchange task attributes # modified_by, last_modified, folder_id, categories, private_flag, color_label # number_of_attachments, lastModifiedOfNewestAttachmentUTC, # title, start_date, end_date, note, alarm, date_completed # priority,status, percent_completed # actual_costs, actual_duration, billing_information, target_costs, target_duration, currency, trip_meter, companies # new columns available only since Rev. 7.6.1 # but: works not for default folder Tasks # start_time,end_time, full_time # endregion # todo.title = utf8(task.title)[:250] # todo.note = utf8(task.note)[:32000] title = task.title if title != todo.title: todo.title = title self.logger.debug(u'Title changed to [%s]' % (title)) note = task.note or u'' if note != todo.note: todo.note = note DAY = 60 * 60 * 24 OX_UTC_TIME = 0 TD_UTC_TIME = 60 * 60 * 12 # if time is not used for UTC start/due date OX uses 00:00 and # Toodledo defaults to 12:00 TD_UTC_TIME changes OX timestamps # to the Toodledo default startdate = task._start_date or 0 if startdate: startdate = startdate - (startdate % DAY) + TD_UTC_TIME if startdate != todo.startdate: self.logger.debug(u'Start date changed to [%s]' % (strflocal(startdate, None))) todo.startdate = startdate starttime = 0 if task.full_time is not None and task.full_time == False: starttime = task._start_time_utc or 0 if starttime != todo.starttime: self.logger.debug(u'Start time changed to [%s]' % (strflocal(starttime, None))) todo.starttime = starttime duedate = task._end_date or 0 if duedate: duedate = duedate - (duedate % DAY) + TD_UTC_TIME if duedate != todo.duedate: self.logger.debug(u'Due date changed to [%s]' % (strflocal(duedate, None))) todo.duedate = duedate duetime = 0 if task.full_time is not None and task.full_time == False: duetime = task._end_time_utc or 0 if duetime != todo.duetime: self.logger.debug(u'Due time changed to [%s]' % (strflocal(duetime, None))) todo.duetime = duetime remind = 0 if task._end_date and task._alarm_date: seconds = task._end_date - task._alarm_date if seconds > 0: remind = seconds / 60 if remind != todo.remind: self.logger.debug(u'Set reminder to %d minutes [%s]' % (remind, strflocal(task._alarm_date, None))) todo.remind = remind if task.status: status = self.status_map[task.status] if status != todo.status: todo.status = status self.logger.debug(u'Status changed to [%s]' % (todo.status)) else: todo.status = 0 if task.priority: priority = self.priority_map[int(task.priority)] if priority != todo.priority: todo.priority = priority self.logger.debug(u'Priority changed to [%s]' % (todo.priority)) else: todo.priority = 0 # todo.folder = tdsync._folder.id tags = [] for tag in task.tag_names(): if tag == tdsync.options.get('ox_tag_star', ','): todo.star = True self.logger.debug(u'Set toodledo star from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('ox_tag_context', ',')): todo.context = tag[1:] self.logger.debug(u'Set toodledo context from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('ox_tag_goal', ',')): todo.goal = tag[1:] self.logger.debug(u'Set toodledo goal from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('ox_tag_location', ',')): todo.location = tag[1:] self.logger.debug(u'Set toodledo location from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('ox_tag_status', ',')): todo.status = ToodledoTask.STATUS.index(tag[1:]) self.logger.debug(u'Set toodledo status from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('ox_tag_priority', ',')): todo.prority = ToodledoTask.PRIORITY[tag[1:]] self.logger.debug(u'Set toodledo priority from [%s]' % (tag)) else: tags.append(tag) self.logger.debug(u'Set toodledo tag from [%s]' % (tag)) if len(tags) > 0: todo.tag = ','.join(tags)[:250] # check completed status and time stamp completed = 0 if OxTask.get_status(task.status) == 'Done': if task.date_completed is not None: # returned only once if status changes to 'Done' completed = task.date_completed / 1000 else: if todo.completed: # stay with previous completd date completed = todo.completed else: # set a new one completed = int(time.time()) if completed != todo.completed: if completed: self.logger.debug(u'Set task completed at [%s]' % (strflocal(completed))) else: self.logger.debug( u'Reset completed date according to status [%s]' % (OxTask.get_status(task.status))) todo.completed = completed return todo
def update(self, other, that=None, this=None, sid=None): todo, task = ThisFromThat.update(self, other, that, this, sid) oxsync = self._engine; ox = self._engine._ox tdsync = self._other; tdapi = self._other.client update = self._update # region Toodledo task attributes # id, title, note, modified, completed, added # folder, context, goal, location, tag, # startdate, duedate, duedatemod, starttime, duetime, # remind, repeat, # status, star, priority, # length, timer # parent, children, order, # meta, previous, attachment, # shared, addedby, via, attachments # endregion # region Open-Xchange task attributes # modified_by, last_modified, folder_id, categories, private_flag, color_label # number_of_attachments, lastModifiedOfNewestAttachmentUTC, # title, start_date, end_date, note, alarm, date_completed # priority,status, percent_completed # actual_costs, actual_duration, billing_information, target_costs, target_duration, currency, trip_meter, companies # new columns available only since Rev. 7.6.1 # but: works not for default folder Tasks # start_time,end_time, full_time # endregion title = utf8(todo.title) if title != task.title: task.title = title self.logger.debug(u'Title changed to [%s]' % (title)) note = utf8(todo.note) if note != task.note: task.note = note DAY = 60*60 * 24 OX_UTC_TIME = 0 TD_UTC_TIME = 60*60 * 12 full_time = None start_time = None start_date = None if todo._start_time: full_time = False start_time = todo._start_time + (ox.utc_offset/1000) if start_time != task.start_time: self.logger.debug(u'Start time changed from [%s] to [%s]' % (strflocal(task.start_time, None), strflocal(start_time, None))) else: if todo._start_date: full_time = True start_date = todo._start_date - TD_UTC_TIME if start_date != task.start_date: self.logger.debug(u'Start date changed from [%s] to [%s]' % (strflocal(task.start_date, None), strflocal(start_date, None))) task.start_time = start_time task.start_date = start_date end_time = None end_date = None if todo._due_time: full_time = False end_time = todo._due_time + (ox.utc_offset/1000) if end_time != task.end_time: self.logger.debug(u'end time changed from [%s] to [%s]' % (strflocal(task.end_time, None), strflocal(end_time, None))) else: if todo._due_date: full_time = True end_date = todo._due_date - TD_UTC_TIME if end_date != task.end_date: self.logger.debug(u'end date changed from [%s] to [%s]' % (strflocal(task.end_date, None), strflocal(end_date, None))) task.end_time = end_time task.end_date = end_date task.full_time = full_time alarm = None if todo._remind_date: alarm = todo._remind_date if alarm != task.alarm: self.logger.debug(u'Reminder changed from [%s] to [%s]' % (strflocal(task.alarm, None), strflocal(alarm, None))) task.alarm = alarm tags = [] prefix_used = [] categories = u'' status = 0 if not todo.completed: if todo.status is not None: status = self.status_map[todo.status] if tdsync.options.get('ox_tag_status'): prefix = tdsync.options.get('ox_tag_status') if todo.status not in [0, 1, 2, 5]: # map to extended status tag tag = prefix + ToodledoTask.STATUS[todo.status] tags.append(tag) prefix_used.append(prefix) self.logger.debug(u'Create extended status tag [%]' % (tag)) else: status = OxTask.get_status('Done') # task.date_completed = todo._date_completed if status != task.status: self.logger.debug(u'Status changed from [%s] to [%s]' % (task.status, status)) task.status = status priority = None if todo.priority is not None: priority = self.priority_map[todo.priority] if tdsync.options.get('ox_tag_priority'): prefix = tdsync.options.get('ox_tag_priority') if todo.priority == -1: tag = utf8(prefix + 'Negative') tags.append(tag) prefix_used.append(prefix) self.logger.debug(u'Create extendend priority tag [%s]' % (tag)) elif todo.priority == 3: tag = utf8(prefix + 'Top') tags.append(tag) prefix_used.append(prefix) self.logger.debug(u'Create extendend priority tag [%s]' % (tag)) else: pass if priority != task.priority: self.logger.debug(u'Priority changed from [%s] to [%s]' % (task.priority, priority)) task.priority = priority if tdsync.options.get('ox_tag_star'): if todo.star: tag = tdsync.options.get('ox_tag_star') tags.append(tag) self.logger.debug(u'Create star tag [%s]' % (tag)) if tdsync.options.get('ox_tag_context'): if todo.context: tag = tdsync.options.get('ox_tag_context') + tdapi.contexts[todo.context]['name'] tags.append(tag) self.logger.debug(u'Create context tag [%s]' % (tag)) if tdsync.options.get('ox_tag_goal'): if todo.goal: tag = tdsync.options.get('ox_tag_goal') + tdapi.goals[todo.goal]['name'] tags.append(tag) self.logger.debug(u'Create goal tag [%s]' % (tag)) if tdsync.options.get('ox_tag_location'): if todo.location: tag = tdsync.options.get('ox_tag_location') + tdapi.locations[todo.location]['name'] tags.append(tag) self.logger.debug(u'Create location tag [%s]' % (tag)) for tag in todo.tag_names(): if tag == tdsync.options.get('ox_tag_star', ','): continue elif tag.startswith(tdsync.options.get('ox_tag_context', ',')): continue elif tag.startswith(tdsync.options.get('ox_tag_goal', ',')): continue elif tag.startswith(tdsync.options.get('ox_tag_location', ',')): continue elif tag.startswith(tdsync.options.get('ox_tag_status', ',')): continue elif tag.startswith(tdsync.options.get('ox_tag_priority', ',')): continue else: tags.append(tag) self.logger.debug(u'Create category tag [%s]' % (tag)) if len(tags) > 0: categories = u','.join(tags) if categories != task.categories: self.logger.debug(u'Categories changed from [%s] to [%s]' % (task.categories, categories)) task.categories = categories task.notification = True task._data['full_time'] = False task = task.update() task.load() self.logger.debug(u'%s: Updating completed with timestamp %s' % (self.class_name, strflocal(task.timestamp))) return task
def update(self, other, that=None, this=None, sid=None): note, todo = ThisFromThat.update(self, other, that, this, sid) tdsync = self._engine; tdapi = self._engine.client ensync = self._other ; enapi = self._other.client update = self._update maxsize = self.options.get('maxsize', 2048) server_url = self.options.get('server_url') # region Toodledo task attributes # id, title, note, modified, completed, added # folder, context, goal, location, tag, # startdate, duedate, duedatemod, starttime, duetime, # remind, repeat, # status, star, priority, # length, timer # parent, children, order, # meta, previous, attachment, # shared, addedby, via, attachments # endregion # region Evernote note attributes # title, content, contentLength, plain, html # attributes.sourceURL # endregion note = note.load() title = utf8(note.title) if title != todo.title: todo.title = title self.logger.debug(u'Title changed to [%s]' % (title)) ######################## # process task content # ######################## content = '' if note.contentLength > maxsize: self.logger.debug(u'%s: Evernote content exceeds limit of %d KB!' % (self.class_name, maxsize/1024)) content += 'Evernote content exceeds limit of %d KB!\n' % (maxsize/1024) else: content += note.plain.strip() + '\n\n' if self.options.get('evernote_sourceURL', True): if note.attributes.sourceURL: if not note.attributes.sourceURL.startswith(server_url): self.logger.debug(u'%s: Updating content with source URL %s' % (self.class_name, note.attributes.sourceURL)) content += 'SOURCE: %s\n\n' % (note.attributes.sourceURL) if self.options.get('evernote_link', True): tag = self.options.get('evernote_link_tag', 'EVERNOTE') content = ensync.add_evernote_link(content, note.edit_url, tag) if self.options.get('evernote_iframe', True): tag = self.options.get('evernote_iframe_tag', 'IFRAME') content = ensync.add_evernote_link(content, note.view_url, tag) content = utf8(content) or u'' if content != todo.note: todo.note = content # self.logger.debug(u'Note changed to [%s]' % (content[:16])) ############################ # process other attributes # ############################ # always update reminderTime from Evernote attribute = self.options.get('evernote_reminderTime') if attribute: if note.attributes.reminderTime: reminderTime = note.attributes.reminderTime/1000 todo[attribute] = reminderTime if attribute == 'duetime': todo['duedate'] = todo['duetime'] if attribute == 'starttime': todo['startdate'] = todo['starttime'] else: todo[attribute] = 0 if attribute == 'duetime': todo['duedate'] = todo['duetime'] if attribute == 'starttime': todo['startdate'] = todo['starttime'] self.logger.debug(u'%s: Updating [%s] from note reminderTime [%s]' % (self.class_name, attribute, strflocal(note.attributes.reminderTime, None))) # always update reminderDoneTime and task status completed = note.attributes.reminderDoneTime/1000 if note.attributes.reminderDoneTime else 0 todo.completed = completed ###################### # process categories # ###################### tags = [] self.logger.debug(u'%s: Updating categories from tags %s' % (self.class_name, note.categories)) for tag in note.tags: if tag == tdsync.options.get('evernote_tag_star', ','): todo.star = True self.logger.debug(u'Set toodledo star from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('evernote_tag_context', ',')): todo.context = tag[1:] self.logger.debug(u'Set toodledo context from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('evernote_tag_goal', ',')): todo.goal = tag[1:] self.logger.debug(u'Set toodledo goal from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('evernote_tag_location', ',')): todo.location = tag[1:] self.logger.debug(u'Set toodledo location from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('evernote_tag_status', ',')): if tag[1:] not in ToodledoTask.STATUS: if self.status_map.get(tag[1:]) is None: self.logger.warning('Ignoring unknown status tag [%s]' % (tag)) status = ToodledoTask.STATUS.index('None') else: status = self.status_map.get(tag[1:]) else: status = ToodledoTask.STATUS.index(tag[1:]) self.logger.debug(u'Set toodledo status from [%s]' % (tag)) todo.status = status elif tag.startswith(tdsync.options.get('evernote_tag_priority', ',')): priority = ToodledoTask.PRIORITY.get(tag[1:]) if priority is None: self.logger.warning('Change unknown priority tag [%s] to [Low]' % (tag)) priority = ToodledoTask.PRIORITY.get(tag[1:], 'Low') else: self.logger.debug(u'Set toodledo priority [%s] from [%s]' % (priority, tag)) todo.priority = priority else: tags.append(utf8(tag)) self.logger.debug(u'Set toodledo tag from [%s]' % (tag)) todo.tag = u'' if len(tags) > 0: todo.tag = u','.join(tags) return todo
def update(self, other, that=None, this=None, sid=None): todo, task = ThisFromThat.update(self, other, that, this, sid) oxsync = self._engine ox = self._engine._ox tdsync = self._other tdapi = self._other.client update = self._update # region Toodledo task attributes # id, title, note, modified, completed, added # folder, context, goal, location, tag, # startdate, duedate, duedatemod, starttime, duetime, # remind, repeat, # status, star, priority, # length, timer # parent, children, order, # meta, previous, attachment, # shared, addedby, via, attachments # endregion # region Open-Xchange task attributes # modified_by, last_modified, folder_id, categories, private_flag, color_label # number_of_attachments, lastModifiedOfNewestAttachmentUTC, # title, start_date, end_date, note, alarm, date_completed # priority,status, percent_completed # actual_costs, actual_duration, billing_information, target_costs, target_duration, currency, trip_meter, companies # new columns available only since Rev. 7.6.1 # but: works not for default folder Tasks # start_time,end_time, full_time # endregion title = utf8(todo.title) if title != task.title: task.title = title self.logger.debug(u'Title changed to [%s]' % (title)) note = utf8(todo.note) if note != task.note: task.note = note DAY = 60 * 60 * 24 OX_UTC_TIME = 0 TD_UTC_TIME = 60 * 60 * 12 full_time = None start_time = None start_date = None if todo._start_time: full_time = False start_time = todo._start_time + (ox.utc_offset / 1000) if start_time != task.start_time: self.logger.debug( u'Start time changed from [%s] to [%s]' % (strflocal( task.start_time, None), strflocal(start_time, None))) else: if todo._start_date: full_time = True start_date = todo._start_date - TD_UTC_TIME if start_date != task.start_date: self.logger.debug( u'Start date changed from [%s] to [%s]' % (strflocal( task.start_date, None), strflocal(start_date, None))) task.start_time = start_time task.start_date = start_date end_time = None end_date = None if todo._due_time: full_time = False end_time = todo._due_time + (ox.utc_offset / 1000) if end_time != task.end_time: self.logger.debug( u'end time changed from [%s] to [%s]' % (strflocal( task.end_time, None), strflocal(end_time, None))) else: if todo._due_date: full_time = True end_date = todo._due_date - TD_UTC_TIME if end_date != task.end_date: self.logger.debug( u'end date changed from [%s] to [%s]' % (strflocal( task.end_date, None), strflocal(end_date, None))) task.end_time = end_time task.end_date = end_date task.full_time = full_time alarm = None if todo._remind_date: alarm = todo._remind_date if alarm != task.alarm: self.logger.debug( u'Reminder changed from [%s] to [%s]' % (strflocal(task.alarm, None), strflocal(alarm, None))) task.alarm = alarm tags = [] prefix_used = [] categories = u'' status = 0 if not todo.completed: if todo.status is not None: status = self.status_map[todo.status] if tdsync.options.get('ox_tag_status'): prefix = tdsync.options.get('ox_tag_status') if todo.status not in [0, 1, 2, 5]: # map to extended status tag tag = prefix + ToodledoTask.STATUS[todo.status] tags.append(tag) prefix_used.append(prefix) self.logger.debug(u'Create extended status tag [%]' % (tag)) else: status = OxTask.get_status('Done') # task.date_completed = todo._date_completed if status != task.status: self.logger.debug(u'Status changed from [%s] to [%s]' % (task.status, status)) task.status = status priority = None if todo.priority is not None: priority = self.priority_map[todo.priority] if tdsync.options.get('ox_tag_priority'): prefix = tdsync.options.get('ox_tag_priority') if todo.priority == -1: tag = utf8(prefix + 'Negative') tags.append(tag) prefix_used.append(prefix) self.logger.debug(u'Create extendend priority tag [%s]' % (tag)) elif todo.priority == 3: tag = utf8(prefix + 'Top') tags.append(tag) prefix_used.append(prefix) self.logger.debug(u'Create extendend priority tag [%s]' % (tag)) else: pass if priority != task.priority: self.logger.debug(u'Priority changed from [%s] to [%s]' % (task.priority, priority)) task.priority = priority if tdsync.options.get('ox_tag_star'): if todo.star: tag = tdsync.options.get('ox_tag_star') tags.append(tag) self.logger.debug(u'Create star tag [%s]' % (tag)) if tdsync.options.get('ox_tag_context'): if todo.context: tag = tdsync.options.get('ox_tag_context') + tdapi.contexts[ todo.context]['name'] tags.append(tag) self.logger.debug(u'Create context tag [%s]' % (tag)) if tdsync.options.get('ox_tag_goal'): if todo.goal: tag = tdsync.options.get('ox_tag_goal') + tdapi.goals[ todo.goal]['name'] tags.append(tag) self.logger.debug(u'Create goal tag [%s]' % (tag)) if tdsync.options.get('ox_tag_location'): if todo.location: tag = tdsync.options.get('ox_tag_location') + tdapi.locations[ todo.location]['name'] tags.append(tag) self.logger.debug(u'Create location tag [%s]' % (tag)) for tag in todo.tag_names(): if tag == tdsync.options.get('ox_tag_star', ','): continue elif tag.startswith(tdsync.options.get('ox_tag_context', ',')): continue elif tag.startswith(tdsync.options.get('ox_tag_goal', ',')): continue elif tag.startswith(tdsync.options.get('ox_tag_location', ',')): continue elif tag.startswith(tdsync.options.get('ox_tag_status', ',')): continue elif tag.startswith(tdsync.options.get('ox_tag_priority', ',')): continue else: tags.append(tag) self.logger.debug(u'Create category tag [%s]' % (tag)) if len(tags) > 0: categories = u','.join(tags) if categories != task.categories: self.logger.debug(u'Categories changed from [%s] to [%s]' % (task.categories, categories)) task.categories = categories task.notification = True task._data['full_time'] = False task = task.update() task.load() self.logger.debug(u'%s: Updating completed with timestamp %s' % (self.class_name, strflocal(task.timestamp))) return task
def update(self, other, that=None, this=None, sid=None): from enapi import ENMLOfPlainText, PlainTextOfENML from oxapi import OxTask task, note = ThisFromThat.update(self, other, that, this, sid) ensync = self._engine ; enapi = self._engine.client oxsync = self._other; ox = self._other._ox update = self._update ox_task_sync = self._other note = note.load() note.title = task.title # set evernote content for new or empty notes if not update: self.logger.debug(u'%s: Updating note content' % (self.class_name)) if task.note is not None: note.content = ENMLOfPlainText(task.note.rstrip()) if self.options.get('ox_sourceURL', True): if note.attributes.sourceURL is None: note.attributes.sourceURL = task.get_url() if self.options.get('ox_sourceApplication'): if note.attributes.sourceApplication is None: note.attributes.sourceApplication = self.options.get('ox_sourceApplication', 'OxPySync') if self.options.get('ox_author'): note.attributes.author = self.options.get('ox_author') else: preserve = None if note.resources: preserve = 'resources' else: if note.attributes.sourceURL: if not re.search(task.ox.server, note.attributes.sourceURL, re.IGNORECASE): preserve = 'source URL' else: if re.sub('\s', '', PlainTextOfENML(note.content), re.MULTILINE): preserve = 'content' if preserve: self.logger.debug(u'%s: Found %s - preserving existing note content' % (self.class_name, preserve)) else: content = task.note if oxsync.options.get('evernote_iframe', 'False'): content = ensync.remove_evernote_link(content, oxsync.options.get('evernote_iframe_tag', 'IFRAME')) if oxsync.options.get('evernote_link', 'False'): content = ensync.remove_evernote_link(content, oxsync.options.get('evernote_link_tag', 'EVERNOTE')) note.content = ENMLOfPlainText(content.rstrip()) self.logger.debug(u'%s: Updating note content' % (self.class_name)) # always update reminderTime attribute = self.options.get('ox_reminderTime','end_time') if task._data.get(attribute): note.attributes.reminderTime = task._data.get(attribute) reminderTime = strflocal(task._data.get(attribute)) else: note.attributes.reminderTime = None note.attributes.reminderOrder = None reminderTime = 'None' self.logger.debug(u'%s: Updating note reminderTime from %s [%s]' % (self.class_name, attribute, reminderTime)) # update note reminder status from task status if OxTask.get_status(task.status) == 'Done': if task._data.get('date_completed') is None: local = time.time() completed = long(local * 1000) else: completed = task.date_completed note.attributes.reminderDoneTime = completed note.attributes.reminderTime = None note.attributes.reminderOrder = None self.logger.debug(u'%s: Updating reminder status from done task [%s]' % (self.class_name, strflocal(completed))) # process categories and tags if task.categories: self.logger.debug(u'%s: Updating tags from categories %s' % (self.class_name, task.categories)) note.tagGuids = [] note.tagNames = task.tagNames else: self.logger.debug(u'%s: Removing tags from note' % (self.class_name)) note.tagGuids = [] note.tagNames = [] if self.options.get('ox_status_tag'): if task.status: tag = self.options['ox_status_tag'] + OxTask.get_status(int(task.status)) self.logger.debug(u'%s: Add status tag %s to note' % (self.class_name, tag)) note.tagNames.append(tag) if self.options.get('ox_priority_tag'): if task.priority: tag = self.options['ox_priority_tag'] + OxTask.get_priority(int(task.priority)) self.logger.debug(u'%s: Add priority tag %s to note' % (self.class_name, tag)) note.tagNames.append(tag) if self.options.get('ox_private_tag'): private_tag = self.options['ox_private_tag'] note_private_tag = False if private_tag in note.tagNames: note_private_tag = True note.tagNames.remove(private_tag) if task.private_flag: note.tagNames.append(private_tag) if not note_private_tag: self.logger.debug(u'%s: Add private tag %s to note' % (self.class_name, private_tag)) else: if note_private_tag: self.logger.debug(u'%s: Remove private tag %s from note' % (self.class_name, private_tag)) # perform the update note = self._engine._book.update_note(note) self.logger.debug(u'%s: Updating completed with timestamp %s' % (self.class_name, strflocal(note.updated))) return note
def update(self, other, that=None, this=None, sid=None): from enapi import ENMLOfPlainText, PlainTextOfENML from oxapi import OxTask todo, note = ThisFromThat.update(self, other, that, this, sid) ensync = self._engine enapi = self._engine.client tdsync = self._other tdapi = self._other.client update = self._update maxsize = self.options.get('maxsize', 2048) note = note.load() note.title = string(todo.title) ############################################### # set evernote content for new or empty notes # ############################################### if not update: self.logger.debug(u'%s: Updating note content' % (self.class_name)) note.content = ENMLOfPlainText(todo.note.rstrip()) if self.options.get('toodledo_sourceURL', True): if note.attributes.sourceURL is None: note.attributes.sourceURL = todo.get_url( tdsync.options.get('permalink_id')) if self.options.get('toodledo_sourceApplication'): if note.attributes.sourceApplication is None: note.attributes.sourceApplication = self.options.get( 'toodledo_sourceApplication', 'PySync') if self.options.get('toodledo_author'): note.attributes.author = self.options.get('toodledo_author') else: preserve = None if note.resources: preserve = 'resources' else: if note.attributes.sourceURL: url = tdsync.options.get('server_url', 'www.toodledo.com') if not re.search(url, note.attributes.sourceURL, re.IGNORECASE): preserve = 'source URL' else: if re.sub('\s', '', PlainTextOfENML(note.content), re.MULTILINE): preserve = 'content' if preserve: self.logger.debug( u'%s: Found %s - preserving existing note content' % (self.class_name, preserve)) else: content = todo.note if tdsync.options.get('evernote_iframe', 'False'): content = ensync.remove_evernote_link( content, tdsync.options.get('evernote_iframe_tag', 'IFRAME')) if tdsync.options.get('evernote_link', 'False'): content = ensync.remove_evernote_link( content, tdsync.options.get('evernote_link_tag', 'EVERNOTE')) note.content = ENMLOfPlainText(content.rstrip()) self.logger.debug(u'%s: Updating note content' % (self.class_name)) ############################## # always update reminderTime # ############################## attribute = self.options.get('toodledo_reminderTime', 'duedate') if todo[attribute]: note.attributes.reminderTime = todo[attribute] * 1000 else: note.attributes.reminderTime = None note.attributes.reminderOrder = None self.logger.debug(u'%s: Updating note reminderTime from %s [%s]' % (self.class_name, attribute, strflocal(note.attributes.reminderTime, None))) ########################### # update reminderDoneTime # ########################### if todo.completed: note.attributes.reminderDoneTime = todo.completed * 1000 note.attributes.reminderTime = None note.attributes.reminderOrder = None else: note.attributes.reminderDoneTime = None self.logger.debug(u'Update reminderDoneTime from [%s]' % (strflocal(todo.completed, None))) ########################## # process lists and tags # ########################## note.tagGuids = [] note.tagNames = [] if tdsync.options.get('evernote_tag_status'): tag = tdsync.options.get( 'evernote_tag_status') + ToodledoTask.STATUS[todo.status] note.tagNames.append(tag) self.logger.debug(u'Create status tag [%s]' % (tag)) if tdsync.options.get('evernote_tag_priority'): tag = tdsync.options.get( 'evernote_tag_priority') + self.priority_map[todo.priority] note.tagNames.append(tag) self.logger.debug(u'Create priority tag [%s]' % (tag)) if tdsync.options.get('evernote_tag_star'): if todo.star: tag = tdsync.options.get('evernote_tag_star') note.tagNames.append(tag) self.logger.debug(u'Create star tag [%s]' % (tag)) if tdsync.options.get('evernote_tag_context'): if todo.context: tag = tdsync.options.get( 'evernote_tag_context') + tdapi.contexts[ todo.context]['name'] note.tagNames.append(tag) self.logger.debug(u'Create context tag [%s]' % (tag)) if tdsync.options.get('evernote_tag_goal'): if todo.goal: tag = tdsync.options.get('evernote_tag_goal') + tdapi.goals[ todo.goal]['name'] note.tagNames.append(tag) self.logger.debug(u'Create goal tag [%s]' % (tag)) if tdsync.options.get('evernote_tag_location'): if todo.location: tag = tdsync.options.get( 'evernote_tag_location') + tdapi.locations[ todo.location]['name'] note.tagNames.append(tag) self.logger.debug(u'Create location tag [%s]' % (tag)) for tag in todo.tag_names(): note.tagNames.append(tag) self.logger.debug(u'Create category tag [%s]' % (tag)) # perform the update (including the necessary encoding) note = self._engine._book.update_note(note) self.logger.debug(u'%s: Updating completed with timestamp %s' % (self.class_name, strflocal(note.updated))) return note
def update(self, other, that=None, this=None, sid=None): task, todo = ThisFromThat.update(self, other, that, this, sid) tdsync = self._engine tdapi = self._engine.client oxsync = self._other ox = self._other._ox update = self._update # region Toodledo task attributes # id, title, note, modified, completed, added # folder, context, goal, location, tag, # startdate, duedate, duedatemod, starttime, duetime, # remind, repeat, # status, star, priority, # length, timer # parent, children, order, # meta, previous, attachment, # shared, addedby, via, attachments # endregion # region Open-Xchange task attributes # modified_by, last_modified, folder_id, categories, private_flag, color_label # number_of_attachments, lastModifiedOfNewestAttachmentUTC, # title, start_date, end_date, note, alarm, date_completed # priority,status, percent_completed # actual_costs, actual_duration, billing_information, target_costs, target_duration, currency, trip_meter, companies # new columns available only since Rev. 7.6.1 # but: works not for default folder Tasks # start_time,end_time, full_time # endregion # todo.title = utf8(task.title)[:250] # todo.note = utf8(task.note)[:32000] title = task.title if title != todo.title: todo.title = title self.logger.debug(u'Title changed to [%s]' % (title)) note = task.note or u'' if note != todo.note: todo.note = note DAY = 60*60 * 24 OX_UTC_TIME = 0 TD_UTC_TIME = 60*60 * 12 # if time is not used for UTC start/due date OX uses 00:00 and # Toodledo defaults to 12:00 TD_UTC_TIME changes OX timestamps # to the Toodledo default startdate = task._start_date or 0 if startdate: startdate = startdate - (startdate % DAY) + TD_UTC_TIME if startdate != todo.startdate: self.logger.debug(u'Start date changed to [%s]' % (strflocal(startdate, None))) todo.startdate = startdate starttime = 0 if task.full_time is not None and task.full_time == False: starttime = task._start_time_utc or 0 if starttime != todo.starttime: self.logger.debug(u'Start time changed to [%s]' % (strflocal(starttime,None))) todo.starttime = starttime duedate = task._end_date or 0 if duedate: duedate = duedate - (duedate % DAY) + TD_UTC_TIME if duedate != todo.duedate: self.logger.debug(u'Due date changed to [%s]' % (strflocal(duedate, None))) todo.duedate = duedate duetime = 0 if task.full_time is not None and task.full_time == False: duetime = task._end_time_utc or 0 if duetime != todo.duetime: self.logger.debug(u'Due time changed to [%s]' % (strflocal(duetime, None))) todo.duetime = duetime remind = 0 if task._end_date and task._alarm_date: seconds = task._end_date - task._alarm_date if seconds > 0: remind = seconds/60 if remind != todo.remind: self.logger.debug(u'Set reminder to %d minutes [%s]' % (remind, strflocal(task._alarm_date, None))) todo.remind = remind if task.status: status = self.status_map[task.status] if status != todo.status: todo.status = status self.logger.debug(u'Status changed to [%s]' % (todo.status)) else: todo.status = 0 if task.priority: priority = self.priority_map[int(task.priority)] if priority != todo.priority: todo.priority = priority self.logger.debug(u'Priority changed to [%s]' % (todo.priority)) else: todo.priority = 0 # todo.folder = tdsync._folder.id tags = [] for tag in task.tag_names(): if tag == tdsync.options.get('ox_tag_star', ','): todo.star = True self.logger.debug(u'Set toodledo star from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('ox_tag_context', ',')): todo.context = tag[1:] self.logger.debug(u'Set toodledo context from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('ox_tag_goal', ',')): todo.goal = tag[1:] self.logger.debug(u'Set toodledo goal from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('ox_tag_location', ',')): todo.location = tag[1:] self.logger.debug(u'Set toodledo location from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('ox_tag_status', ',')): todo.status = ToodledoTask.STATUS.index(tag[1:]) self.logger.debug(u'Set toodledo status from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('ox_tag_priority', ',')): todo.prority = ToodledoTask.PRIORITY[tag[1:]] self.logger.debug(u'Set toodledo priority from [%s]' % (tag)) else: tags.append(tag) self.logger.debug(u'Set toodledo tag from [%s]' % (tag)) if len(tags) > 0: todo.tag = ','.join(tags)[:250] # check completed status and time stamp completed = 0 if OxTask.get_status(task.status) == 'Done': if task.date_completed is not None: # returned only once if status changes to 'Done' completed = task.date_completed/1000 else: if todo.completed: # stay with previous completd date completed = todo.completed else: # set a new one completed = int(time.time()) if completed != todo.completed: if completed: self.logger.debug(u'Set task completed at [%s]' % (strflocal(completed))) else: self.logger.debug(u'Reset completed date according to status [%s]' % (OxTask.get_status(task.status))) todo.completed = completed return todo
def update(self, other, that=None, this=None, sid=None): note, todo = ThisFromThat.update(self, other, that, this, sid) tdsync = self._engine tdapi = self._engine.client ensync = self._other enapi = self._other.client update = self._update maxsize = self.options.get('maxsize', 2048) server_url = self.options.get('server_url') # region Toodledo task attributes # id, title, note, modified, completed, added # folder, context, goal, location, tag, # startdate, duedate, duedatemod, starttime, duetime, # remind, repeat, # status, star, priority, # length, timer # parent, children, order, # meta, previous, attachment, # shared, addedby, via, attachments # endregion # region Evernote note attributes # title, content, contentLength, plain, html # attributes.sourceURL # endregion note = note.load() title = utf8(note.title) if title != todo.title: todo.title = title self.logger.debug(u'Title changed to [%s]' % (title)) ######################## # process task content # ######################## content = '' if note.contentLength > maxsize: self.logger.debug(u'%s: Evernote content exceeds limit of %d KB!' % (self.class_name, maxsize / 1024)) content += 'Evernote content exceeds limit of %d KB!\n' % ( maxsize / 1024) else: content += note.plain.strip() + '\n\n' if self.options.get('evernote_sourceURL', True): if note.attributes.sourceURL: if not note.attributes.sourceURL.startswith(server_url): self.logger.debug( u'%s: Updating content with source URL %s' % (self.class_name, note.attributes.sourceURL)) content += 'SOURCE: %s\n\n' % (note.attributes.sourceURL) if self.options.get('evernote_link', True): tag = self.options.get('evernote_link_tag', 'EVERNOTE') content = ensync.add_evernote_link(content, note.edit_url, tag) if self.options.get('evernote_iframe', True): tag = self.options.get('evernote_iframe_tag', 'IFRAME') content = ensync.add_evernote_link(content, note.view_url, tag) content = utf8(content) or u'' if content != todo.note: todo.note = content # self.logger.debug(u'Note changed to [%s]' % (content[:16])) ############################ # process other attributes # ############################ # always update reminderTime from Evernote attribute = self.options.get('evernote_reminderTime') if attribute: if note.attributes.reminderTime: reminderTime = note.attributes.reminderTime / 1000 todo[attribute] = reminderTime if attribute == 'duetime': todo['duedate'] = todo['duetime'] if attribute == 'starttime': todo['startdate'] = todo['starttime'] else: todo[attribute] = 0 if attribute == 'duetime': todo['duedate'] = todo['duetime'] if attribute == 'starttime': todo['startdate'] = todo['starttime'] self.logger.debug( u'%s: Updating [%s] from note reminderTime [%s]' % (self.class_name, attribute, strflocal(note.attributes.reminderTime, None))) # always update reminderDoneTime and task status completed = note.attributes.reminderDoneTime / 1000 if note.attributes.reminderDoneTime else 0 todo.completed = completed ###################### # process categories # ###################### tags = [] self.logger.debug(u'%s: Updating categories from tags %s' % (self.class_name, note.categories)) for tag in note.tags: if tag == tdsync.options.get('evernote_tag_star', ','): todo.star = True self.logger.debug(u'Set toodledo star from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('evernote_tag_context', ',')): todo.context = tag[1:] self.logger.debug(u'Set toodledo context from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('evernote_tag_goal', ',')): todo.goal = tag[1:] self.logger.debug(u'Set toodledo goal from [%s]' % (tag)) elif tag.startswith( tdsync.options.get('evernote_tag_location', ',')): todo.location = tag[1:] self.logger.debug(u'Set toodledo location from [%s]' % (tag)) elif tag.startswith(tdsync.options.get('evernote_tag_status', ',')): if tag[1:] not in ToodledoTask.STATUS: if self.status_map.get(tag[1:]) is None: self.logger.warning( 'Ignoring unknown status tag [%s]' % (tag)) status = ToodledoTask.STATUS.index('None') else: status = self.status_map.get(tag[1:]) else: status = ToodledoTask.STATUS.index(tag[1:]) self.logger.debug(u'Set toodledo status from [%s]' % (tag)) todo.status = status elif tag.startswith( tdsync.options.get('evernote_tag_priority', ',')): priority = ToodledoTask.PRIORITY.get(tag[1:]) if priority is None: self.logger.warning( 'Change unknown priority tag [%s] to [Low]' % (tag)) priority = ToodledoTask.PRIORITY.get(tag[1:], 'Low') else: self.logger.debug(u'Set toodledo priority [%s] from [%s]' % (priority, tag)) todo.priority = priority else: tags.append(utf8(tag)) self.logger.debug(u'Set toodledo tag from [%s]' % (tag)) todo.tag = u'' if len(tags) > 0: todo.tag = u','.join(tags) return todo
def update(self, other, that=None, this=None, sid=None): note, task = ThisFromThat.update(self, other, that, this, sid) ox = self._engine._ox ensync = self._other maxsize = self._engine.maxsize update = self._update from oxsync import OxTaskSync from oxapi import OxTask note = note.load() task._data['title'] = note.title if update: # update task from if task.number_of_attachments > 0: for attachment in ox.get_attachments(task): if attachment.filename.startswith(note.guid): attachment.detach() # optional store evernote content as attachment if self.options.get('evernote_html', False): task.upload([{'content': note.html, 'mimetype': 'text/html', 'name': note.guid + '.html'}]) if self.options.get('evernote_enml', False): task.upload([{'content': note.content, 'mimetype': 'text/xml', 'name': note.guid + '.enml'}]) # reload and update timestamp task = task.load() ######################## # process task content # ######################## content = '' if self.options.get('evernote_sourceURL', True): if note.attributes.sourceURL: if not note.attributes.sourceURL.startswith(ox.server): self.logger.debug(u'%s: Updating content with source URL %s' % (self.class_name, note.attributes.sourceURL)) content += 'SOURCE: %s\n' % (note.attributes.sourceURL) if note.contentLength > maxsize: self.logger.debug(u'%s: Evernote content exceeds limit of %d KB!' % (self.class_name, maxsize/1024)) content += 'Evernote content exceeds limit of %d KB!' % (maxsize/1024) else: content += note.plain if self.options.get('evernote_link', True): tag = self.options.get('evernote_link_tag', 'EVERNOTE') content = ensync.add_evernote_link(content, note.edit_url, tag) if self.options.get('evernote_iframe', True): tag = self.options.get('evernote_iframe_tag', 'IFRAME') content = ensync.add_evernote_link(content, note.view_url, tag) task._data['note'] = content ############################ # process other attributes # ############################ # always update reminderTime from Evernote newtime = strflocal(note.attributes.reminderTime) if note.attributes.reminderTime is not None else 'None' attribute = self.options.get('evernote_reminderTime', 'end_date') task._data[attribute] = note.attributes.reminderTime self.logger.debug(u'%s: Updating %s from note reminderTime [%s]' % (self.class_name, attribute, newtime)) # always update reminderDoneTime and task status oldstatus = int(task._data.get('status', 0)) if note.attributes.reminderDoneTime is not None: newtime = strflocal(note.attributes.reminderTime) newstatus = OxTask.get_status('done') else: newtime = None if task._data.get('status') and OxTask.get_status(int(task._data['status'])) == 'Done': # reset task status newstatus = int(OxTask.get_status('In progress')) else: # don't change newstatus = int(task._data.get('status', 0)) attribute = self.options.get('evernote_reminderDoneTime', 'date_completed') task._data[attribute] = note.attributes.reminderDoneTime self.logger.debug(u'%s: Updating task %s from note reminderDoneTime [%s]' % (self.class_name, attribute, newtime)) task._data['status'] = newstatus if newstatus != oldstatus: self.logger.debug(u'%s: Updating task status from [%s] to [%s]' % (self.class_name, OxTask.get_status(oldstatus), OxTask.get_status(newstatus))) ###################### # process categories # ###################### self.logger.debug(u'%s: Updating categories from tags %s' % (self.class_name, note.categories)) status_prefix = None status_now = task.status status_new = status_now if self.options.get('evernote_tag_status'): status_prefix = unicode(self.options['evernote_tag_status']) status_new = OxTask.get_status('Not started') priority_prefix = None priority_now = int(task.priority) if task.priority is not None else None priority_new = priority_now if self.options.get('evernote_tag_priority'): priority_prefix = unicode(self.options['evernote_tag_priority']) priority_new = OxTask.get_priority('None') private_tag = None private_new = task.private_flag private_now = task.private_flag if self.options.get('evernote_tag_private'): private_tag = unicode(self.options['evernote_tag_private']) private_new = False categories = [] for tag in note.categories.split(','): if status_prefix and tag.startswith(status_prefix): status_new = OxTask.get_status(tag[1:].lower()) if status_now != status_new: self.logger.debug(u'%s: Updating task status to [%s]' % (self.class_name, OxTask.get_status(status_new))) elif priority_prefix and tag.startswith(priority_prefix): priority_new = OxTask.get_priority(tag[1:].lower()) if priority_now != priority_new: self.logger.debug(u'%s: Updating task priority to [%s]' % (self.class_name, OxTask.get_priority(priority_new))) elif private_tag and tag == private_tag: private_new = True if private_now != private_new: self.logger.debug(u'%s: Updating private flag to [%s]' % (self.class_name, private_new)) else: categories.append(tag) task._data['status'] = status_new if priority_new == 0: # undocumented OX magic task._data['priority'] = 'null' else: task._data['priority'] = str(priority_new) task._data['private_flag'] = private_new # OxTask @categories.setter task.categories = categories task._data['title'] = note.title task._data['full_time'] = True task._data['notification'] = True task = task.update() task.load() # timestamp from api request is UTC: don't add self._utc_offset self.logger.debug(u'%s: Updating completed with timestamp %s' % (self.class_name, strflocal(task.timestamp))) return task
def update(self, other, that=None, this=None, sid=None): note, task = ThisFromThat.update(self, other, that, this, sid) ox = self._engine._ox ensync = self._other maxsize = self._engine.maxsize update = self._update from oxsync import OxTaskSync from oxapi import OxTask note = note.load() task._data['title'] = note.title if update: # update task from if task.number_of_attachments > 0: for attachment in ox.get_attachments(task): if attachment.filename.startswith(note.guid): attachment.detach() # optional store evernote content as attachment if self.options.get('evernote_html', False): task.upload([{ 'content': note.html, 'mimetype': 'text/html', 'name': note.guid + '.html' }]) if self.options.get('evernote_enml', False): task.upload([{ 'content': note.content, 'mimetype': 'text/xml', 'name': note.guid + '.enml' }]) # reload and update timestamp task = task.load() ######################## # process task content # ######################## content = '' if self.options.get('evernote_sourceURL', True): if note.attributes.sourceURL: if not note.attributes.sourceURL.startswith(ox.server): self.logger.debug( u'%s: Updating content with source URL %s' % (self.class_name, note.attributes.sourceURL)) content += 'SOURCE: %s\n' % (note.attributes.sourceURL) if note.contentLength > maxsize: self.logger.debug(u'%s: Evernote content exceeds limit of %d KB!' % (self.class_name, maxsize / 1024)) content += 'Evernote content exceeds limit of %d KB!' % (maxsize / 1024) else: content += note.plain if self.options.get('evernote_link', True): tag = self.options.get('evernote_link_tag', 'EVERNOTE') content = ensync.add_evernote_link(content, note.edit_url, tag) if self.options.get('evernote_iframe', True): tag = self.options.get('evernote_iframe_tag', 'IFRAME') content = ensync.add_evernote_link(content, note.view_url, tag) task._data['note'] = content ############################ # process other attributes # ############################ # always update reminderTime from Evernote newtime = strflocal( note.attributes.reminderTime ) if note.attributes.reminderTime is not None else 'None' attribute = self.options.get('evernote_reminderTime', 'end_date') task._data[attribute] = note.attributes.reminderTime self.logger.debug(u'%s: Updating %s from note reminderTime [%s]' % (self.class_name, attribute, newtime)) # always update reminderDoneTime and task status oldstatus = int(task._data.get('status', 0)) if note.attributes.reminderDoneTime is not None: newtime = strflocal(note.attributes.reminderTime) newstatus = OxTask.get_status('done') else: newtime = None if task._data.get('status') and OxTask.get_status( int(task._data['status'])) == 'Done': # reset task status newstatus = int(OxTask.get_status('In progress')) else: # don't change newstatus = int(task._data.get('status', 0)) attribute = self.options.get('evernote_reminderDoneTime', 'date_completed') task._data[attribute] = note.attributes.reminderDoneTime self.logger.debug( u'%s: Updating task %s from note reminderDoneTime [%s]' % (self.class_name, attribute, newtime)) task._data['status'] = newstatus if newstatus != oldstatus: self.logger.debug(u'%s: Updating task status from [%s] to [%s]' % (self.class_name, OxTask.get_status(oldstatus), OxTask.get_status(newstatus))) ###################### # process categories # ###################### self.logger.debug(u'%s: Updating categories from tags %s' % (self.class_name, note.categories)) status_prefix = None status_now = task.status status_new = status_now if self.options.get('evernote_tag_status'): status_prefix = unicode(self.options['evernote_tag_status']) status_new = OxTask.get_status('Not started') priority_prefix = None priority_now = int( task.priority) if task.priority is not None else None priority_new = priority_now if self.options.get('evernote_tag_priority'): priority_prefix = unicode(self.options['evernote_tag_priority']) priority_new = OxTask.get_priority('None') private_tag = None private_new = task.private_flag private_now = task.private_flag if self.options.get('evernote_tag_private'): private_tag = unicode(self.options['evernote_tag_private']) private_new = False categories = [] for tag in note.categories.split(','): if status_prefix and tag.startswith(status_prefix): status_new = OxTask.get_status(tag[1:].lower()) if status_now != status_new: self.logger.debug( u'%s: Updating task status to [%s]' % (self.class_name, OxTask.get_status(status_new))) elif priority_prefix and tag.startswith(priority_prefix): priority_new = OxTask.get_priority(tag[1:].lower()) if priority_now != priority_new: self.logger.debug( u'%s: Updating task priority to [%s]' % (self.class_name, OxTask.get_priority(priority_new))) elif private_tag and tag == private_tag: private_new = True if private_now != private_new: self.logger.debug(u'%s: Updating private flag to [%s]' % (self.class_name, private_new)) else: categories.append(tag) task._data['status'] = status_new if priority_new == 0: # undocumented OX magic task._data['priority'] = 'null' else: task._data['priority'] = str(priority_new) task._data['private_flag'] = private_new # OxTask @categories.setter task.categories = categories task._data['title'] = note.title task._data['full_time'] = True task._data['notification'] = True task = task.update() task.load() # timestamp from api request is UTC: don't add self._utc_offset self.logger.debug(u'%s: Updating completed with timestamp %s' % (self.class_name, strflocal(task.timestamp))) return task
def update(self, other, that=None, this=None, sid=None): from enapi import ENMLOfPlainText, PlainTextOfENML from oxapi import OxTask todo, note = ThisFromThat.update(self, other, that, this, sid) ensync = self._engine ; enapi = self._engine.client tdsync = self._other; tdapi = self._other.client update = self._update maxsize = self.options.get('maxsize', 2048) note = note.load() note.title = string(todo.title) ############################################### # set evernote content for new or empty notes # ############################################### if not update: self.logger.debug(u'%s: Updating note content' % (self.class_name)) note.content = ENMLOfPlainText(todo.note.rstrip()) if self.options.get('toodledo_sourceURL', True): if note.attributes.sourceURL is None: note.attributes.sourceURL = todo.get_url(tdsync.options.get('permalink_id')) if self.options.get('toodledo_sourceApplication'): if note.attributes.sourceApplication is None: note.attributes.sourceApplication = self.options.get('toodledo_sourceApplication', 'PySync') if self.options.get('toodledo_author'): note.attributes.author = self.options.get('toodledo_author') else: preserve = None if note.resources: preserve = 'resources' else: if note.attributes.sourceURL: url = tdsync.options.get('server_url','www.toodledo.com') if not re.search(url, note.attributes.sourceURL, re.IGNORECASE): preserve = 'source URL' else: if re.sub('\s', '', PlainTextOfENML(note.content), re.MULTILINE): preserve = 'content' if preserve: self.logger.debug(u'%s: Found %s - preserving existing note content' % (self.class_name, preserve)) else: content = todo.note if tdsync.options.get('evernote_iframe', 'False'): content = ensync.remove_evernote_link(content, tdsync.options.get('evernote_iframe_tag', 'IFRAME')) if tdsync.options.get('evernote_link', 'False'): content = ensync.remove_evernote_link(content, tdsync.options.get('evernote_link_tag', 'EVERNOTE')) note.content = ENMLOfPlainText(content.rstrip()) self.logger.debug(u'%s: Updating note content' % (self.class_name)) ############################## # always update reminderTime # ############################## attribute = self.options.get('toodledo_reminderTime','duedate') if todo[attribute]: note.attributes.reminderTime = todo[attribute] * 1000 else: note.attributes.reminderTime = None note.attributes.reminderOrder = None self.logger.debug(u'%s: Updating note reminderTime from %s [%s]' % (self.class_name, attribute, strflocal(note.attributes.reminderTime, None))) ########################### # update reminderDoneTime # ########################### if todo.completed: note.attributes.reminderDoneTime = todo.completed * 1000 note.attributes.reminderTime = None note.attributes.reminderOrder = None else: note.attributes.reminderDoneTime = None self.logger.debug(u'Update reminderDoneTime from [%s]' % (strflocal(todo.completed, None))) ########################## # process lists and tags # ########################## note.tagGuids = [] note.tagNames = [] if tdsync.options.get('evernote_tag_status'): tag = tdsync.options.get('evernote_tag_status') + ToodledoTask.STATUS[todo.status] note.tagNames.append(tag) self.logger.debug(u'Create status tag [%s]' % (tag)) if tdsync.options.get('evernote_tag_priority'): tag = tdsync.options.get('evernote_tag_priority') + self.priority_map[todo.priority] note.tagNames.append(tag) self.logger.debug(u'Create priority tag [%s]' % (tag)) if tdsync.options.get('evernote_tag_star'): if todo.star: tag = tdsync.options.get('evernote_tag_star') note.tagNames.append(tag) self.logger.debug(u'Create star tag [%s]' % (tag)) if tdsync.options.get('evernote_tag_context'): if todo.context: tag = tdsync.options.get('evernote_tag_context') + tdapi.contexts[todo.context]['name'] note.tagNames.append(tag) self.logger.debug(u'Create context tag [%s]' % (tag)) if tdsync.options.get('evernote_tag_goal'): if todo.goal: tag = tdsync.options.get('evernote_tag_goal') + tdapi.goals[todo.goal]['name'] note.tagNames.append(tag) self.logger.debug(u'Create goal tag [%s]' % (tag)) if tdsync.options.get('evernote_tag_location'): if todo.location: tag = tdsync.options.get('evernote_tag_location') + tdapi.locations[todo.location]['name'] note.tagNames.append(tag) self.logger.debug(u'Create location tag [%s]' % (tag)) for tag in todo.tag_names(): note.tagNames.append(tag) self.logger.debug(u'Create category tag [%s]' % (tag)) # perform the update (including the necessary encoding) note = self._engine._book.update_note(note) self.logger.debug(u'%s: Updating completed with timestamp %s' % (self.class_name, strflocal(note.updated))) return note