Beispiel #1
0
    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()