def push_task(self, task_id, task, extra): """ Push task from Todoist to Evernote and save extra information in the "extra" field """ client = utils.get_evernote_client(self.user) note_store = client.get_note_store() if task_id: try: note = note_store.getNote(task_id, True, True, False, False) create = False except EDAMNotFoundException: note = Types.Note() create = True else: note = Types.Note() create = True note.title = plaintext_content(task.content, cut_url_pattern='evernote.com') if create: note.content = utils.format_note_content('') note.notebookGuid = self.notebook_guid note.attributes = Types.NoteAttributes() note.attributes.reminderOrder = REMINDER_BASE_TIME - task.item_order if task.checked: note.attributes.reminderDoneTime = int(time.time()) else: note.attributes.reminderDoneTime = None if task.due_date: due_date_ms = int((task.due_date - EPOCH).total_seconds()) * 1000 note.attributes.reminderTime = due_date_ms else: note.attributes.reminderTime = None if create: note = note_store.createNote(note) else: note = note_store.updateNote(note) new_extra = { 'original_content': task.content, 'original_due_date': task.due_date, 'original_date_string': task.date_string, } return note.guid, new_extra
def push_task(self, task_id, task, extra): """ Push task from Todoist to Evernote and save extra information in the "extra" field """ client = utils.get_evernote_client(self.user) note_store = client.get_note_store() if task_id: try: note = note_store.getNote(task_id, True, True, False, False) create = False except EDAMNotFoundException: note = Types.Note() create = True else: note = Types.Note() create = True note.title = plaintext_content(task.content, cut_url_pattern="evernote.com") if create: note.content = utils.format_note_content("") note.notebookGuid = self.notebook_guid note.attributes = Types.NoteAttributes() note.attributes.reminderOrder = REMINDER_BASE_TIME - task.item_order if task.checked: note.attributes.reminderDoneTime = int(time.time()) else: note.attributes.reminderDoneTime = None if task.due_date: due_date_ms = int((task.due_date - EPOCH).total_seconds()) * 1000 note.attributes.reminderTime = due_date_ms else: note.attributes.reminderTime = None if create: note = note_store.createNote(note) else: note = note_store.updateNote(note) new_extra = { "original_content": task.content, "original_due_date": task.due_date, "original_date_string": task.date_string, } return note.guid, new_extra
def push_task(self, task_id, task, extra): """ Push task from Todoist to Google Calendar and save extra information in the "extra" field. If the task is in_history, we delete the event """ user = self.bridge.integration.user client = utils.get_authorized_client(user) logging_extra = {'task_id': task_id, 'task': task, 'extra': extra} if not task.due_date or task.due_date.second == 59: # ignore this task or try to delete it if task_id: logger.debug("Delete GCal event because Todoist task " "doesn't have a date anymore", extra=logging_extra) self.delete_task(task_id, extra) return None, None orig_event = None create = True # try to get orig event if task_id: try: orig_event = utils.json_get(client, '/calendars/%s/events/%s' % (self.get_calendar_id(), task_id)) create = False except HTTPError: pass if create: task_id = uuid.uuid4().hex event_duration = get_event_duration(orig_event) event_content = plaintext_content(task.content, cut_all_urls=True) attrs = { 'summary': event_content, 'start': { 'dateTime': generate_date(task.due_date, accept_naive=True), }, 'end': { 'dateTime': generate_date(task.due_date + event_duration, accept_naive=True), } } if create: attrs['id'] = task_id if create: command = utils.json_post url = '/calendars/%s/events' % self.get_calendar_id() else: command = utils.json_put url = '/calendars/%s/events/%s' % (self.get_calendar_id(), task_id) resp = command(client, url, **attrs) logger.debug('Create GCal event', extra=dict(logging_extra, server_url=url, server_response=resp)) new_extra = { 'original_content': task.content, 'original_due_date': task.due_date, 'original_date_string': task.date_string, } return task_id, new_extra