def get_synced_notes(cls, user_profile, parent_project): evernote_profile = user_profile.evernote_profile auth_token = evernote_profile.auth_token evernote_helper = EvernoteHelper(evernote_profile) note_store = evernote_helper.note_store current_state = evernote_helper.current_state_count if evernote_profile.latest_update_count < current_state: new_notes = evernote_helper.get_metadata_notes(evernote_profile, parent_project) # Look for removed notes """guid_new_notes = [en.guid for en in new_notes.notes] removed_notes = [n for n in parent_project.notes if n.evernote_guid not in guid_new_notes] for f in removed_notes: parent_project.notes.remove(f)""" for metadata_note in new_notes.notes: # look for note in db notes = parent_project.notes local_note = filter(lambda n: n.evernote_guid == metadata_note.guid, notes) # If found the note we update the note if len(local_note) is 1 and local_note[0].evernote_usn < metadata_note.updateSequenceNum: full_note = note_store.getNote(auth_token, metadata_note.guid, True, True, False, False) local_note = local_note[0] local_note = evernote_helper.copy_evernote_note(full_note, local_note) # If not found, a new note is created elif len(local_note) is not 1: full_note = note_store.getNote(auth_token, metadata_note.guid, True, True, False, False) local_note = Note() local_note = evernote_helper.copy_evernote_note(full_note, local_note) parent_project.notes.append(local_note) evernote_profile.latest_update_count = current_state user_profile.save() parent_project.save()
def create_note_evernote(self, user_profile, project): auth_token = user_profile.evernote_profile.auth_token evernote_helper = EvernoteHelper(user_profile.evernote_profile) noteStore = evernote_helper.note_store note = evernote_helper.create_note(self.title, self.content, project) try: created_note = noteStore.createNote(auth_token, note) except Errors.EDAMUserException as e: return None except Errors.EDAMNotFoundException as e: return None except Exception as e: raise e # If note is synced fine the usn is updated user_profile.evernote_profile.latest_update_count = created_note.updateSequenceNum user_profile.save() self.evernote_usn = created_note.updateSequenceNum self.evernote_guid = created_note.guid project.notes[int(self.id)] = self project.save() return created_note
def dehydrate_content(self, bundle): if hasattr(bundle.request, 'user'): user_profile = UserProfile.objects.get(user = bundle.request.user) if user_profile.is_evernote_synced: ev_h = EvernoteHelper(user_profile.evernote_profile) return ev_h.replace_images(bundle.obj.content, bundle.obj.evernote_guid) else: return bundle.obj.content