A Django/python wrapper and example for the Evernote API
Feel free to fork, devlop and submit pull requests for this project on your own, or let me know if there's any specific functionality you want included. You're welcome to use this for your django/evernote app, just let me know that you're using it!
N.B. The only apps you need are evernote_api, evernote and thrift. The rest are there for demonstration purposes.
- Beautifulsoup for XML parsing
- The Evernote Python SDK (provided as evernote/)
- A Python implementation of the Thrift protocol (provided as thrift/)
Download the repository.
Remove everything but the three folders evernote_api, evernote and thrift.
Add evernote, evernote_api, thrift and bs4 to your INSTALLED_APPS.
Add the following settings to your settings.py:
EVERNOTE_HOST # sandbox.evernote.com for dev EVERNOTE_KEY # Your Evernote consumer key EVERNOTE_SECRET # Your Evernote secret key EVERNOTE_OAUTH_COMPLETE_URL # Redirect URL after the OAuth flow EVERNOTE_OAUTH_TOKEN_VALIDITY # OAuth token validity in days
The following is an example for sending a user through the OAuth flow:
from evernote_api import EvernoteAPI everAPI = EvernoteAPI() callback_url = request.build_absolute_url(everAPI.token_callback_url) return everAPI.get_token(request, callback_url)
The user goes through the OAuth flow and ends up at the url specified in settings.EVERNOTE_OAUTH_COMPLETE_URL. From the view that handles that url, the token and related info is stored in four session variables:
request.session['oauth_token'] # stores the OAuth token request.session['expires'] # stores the token expires time request.session['edam_shard'] # stores the shard the user belongs to request.session['edam_userId'] # stores the user id
Remember to extract these and then delete them from the session.
Notestore API calls
All notestore calls must use an EvernoteAPI instance created with the user's oauth token and shard number. See the following example:
profile = request.user.profile everAPI = EvernoteAPI(profile.evernote_token, profile.evernote_shard) tagged = everAPI.get_notes_with_tag("sometag")
Currently, following API calls are implemented :
EvernoteAPI.get_notes_with_tag(self, tag) # gets notes with a specific tag EvernoteAPI.get_note_text(self, note_guid) # gets the text of a note
To implement more functions, refer to the Evernote API reference and write the calls using EvernoteAPI's internal convenience function _get_note_store. Take a look at the two example functions written thus far as a guide for the function calls and datatypes.