-
-
Save ciiqr/11195532 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
def makeNote(authToken, noteStore, noteTitle, noteBody, resources=[], parentNotebook=None): | |
""" | |
Create a Note instance with title and body | |
Send Note object to user's account | |
""" | |
ourNote = Types.Note() | |
ourNote.title = noteTitle | |
## Build body of note | |
nBody = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" | |
nBody += "<!DOCTYPE en-note SYSTEM \"http://xml.evernote.com/pub/enml2.dtd\">" | |
nBody += "<en-note>%s" % noteBody | |
if resources: | |
### Add Resource objects to note body | |
nBody += "<br />" * 2 | |
ourNote.resources = resources | |
for resource in resources: | |
hexhash = binascii.hexlify(resource.data.bodyHash) | |
nBody += "Attachment with hash %s: <br /><en-media type=\"%s\" hash=\"%s\" /><br />" % \ | |
(hexhash, resource.mime, hexhash) | |
nBody += "</en-note>" | |
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