Question

I'm aware that the Evernote Python API provides a method called getNote if I get a special API key.

However, this is all overkill for my desired application: to use Python to textually analyze my own personal Evernotes. Even using the API seems like overkill, since it is more geared toward app developers.

Is there an easier way to access my own personal Evernotes in Python by name of note and read their content?

Was it helpful?

Solution

That special API Key you mentioned is for OAuth, which is overkill for some app that accesses only your own account. Evernote has a developer token for that purpose.

Below is a simple example how you can get a note with title.

import evernote.edam.type.ttypes as Types
import evernote.edam.notestore.ttypes as NoteStore

from evernote.api.client import EvernoteClient

auth_token = "your developer token"

client = EvernoteClient(token=auth_token, sandbox=True)
note_store = client.get_note_store()

note_filter = NoteStore.NoteFilter()
note_filter.words = 'intitle:"test"'
notes_metadata_result_spec = NoteStore.NotesMetadataResultSpec()

notes_metadata_list = note_store.findNotesMetadata(note_filter, 0, 1, notes_metadata_result_spec)
note_guid = notes_metadata_list.notes[0].guid
note = note_store.getNote(note_guid, True, False, False, False)

OTHER TIPS

The most straightforward solution I can see is to search the Evernote content folder for unique contents from each note. It is found here:

/Users/[system_username]/Library/Application Support/Evernote/accounts/Evernote/[evernote_username]/content/

The titles of the notes are not listed in the content folders, so you will have to map them manually to their associated folder. For example, notes titled 'Monday' to 'Sunday' could be mapped in a dictionary like so:

day = {
    'Monday': 'p1647',
    'Tuesday': 'p1648',
    'Wednesday': 'p1622',
    'Thursday': 'p1620',
    'Friday': 'p1641',
    'Saturday': 'p1644',
    'Sunday': 'p1635',
}

The contents of Evernotes are stored in content.html files in their respective p\d+ folder. They can be accessed as strings by the following function:

import os
def getHTML(note_folder):
    system_username = 'your_username'
    evernote_username = 'your_username'
    base_dir = '/Users/'+system_username+'/Library/Application Support/Evernote/accounts/Evernote/'+evernote_username+'/content/'
    f = open(os.path.join(base_dir,note_folder,'content.html'), 'r')
    return f.read()

You can parse the HTML using BeautifulSoup. This will print all the lines in a simple note:

from BeautifulSoup import BeautifulSoup
html = getHTML(day['Monday'])
soup = BeautifulSoup(html)

divs = soup.findAll('div')
for div in divs:
    if len(div.contents) == 1:
        s = div.contents[0]
        if div.br != None:
            s = ''
        print s
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top