-
-
Save julen/6ad44810115e62cc3a0ef5c9a9cd7e72 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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