Skip to content

Instantly share code, notes, and snippets.

@evernotegists
Last active July 27, 2017 18:13
Show Gist options
  • Save evernotegists/5313822 to your computer and use it in GitHub Desktop.
Save evernotegists/5313822 to your computer and use it in GitHub Desktop.
from evernote.edam.type import ttypes
def makeNote(authToken, noteStore, noteTitle, noteBody, parentNotebook=None):
nBody = '<?xml version="1.0" encoding="UTF-8"?>'
nBody += '<!DOCTYPE en-note SYSTEM "http://xml.evernote.com/pub/enml2.dtd">'
nBody += '<en-note>%s</en-note>' % noteBody
## Create note object
ourNote = ttypes.Note()
ourNote.title = noteTitle
ourNote.content = nBody
## parentNotebook is optional; if omitted, default notebook is used
if parentNotebook and hasattr(parentNotebook, 'guid'):
ourNote.notebookGuid = parentNotebook.guid
## Attempt to create note in Evernote account
try:
note = noteStore.createNote(authToken, ourNote)
except Errors.EDAMUserException, edue:
## Something was wrong with the note data
## See EDAMErrorCode enumeration for error code explanation
## http://dev.evernote.com/documentation/reference/Errors.html#Enum_EDAMErrorCode
print "EDAMUserException:", edue
return None
except Errors.EDAMNotFoundException, ednfe:
## Parent Notebook GUID doesn't correspond to an actual notebook
print "EDAMNotFoundException: Invalid parent notebook GUID"
return None
## Return created note object
return note
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment