Skip to content

Instantly share code, notes, and snippets.

@evernotegists
Created May 13, 2015 22:55
Show Gist options
  • Save evernotegists/69784c03f77ceae63208 to your computer and use it in GitHub Desktop.
Save evernotegists/69784c03f77ceae63208 to your computer and use it in GitHub Desktop.
Getting a Thumbnails of a Evernote note using Python
'''This is a script that writes jpg thumbnails for each note in a specified notebook to the currect directory'''
from evernote.api.client import EvernoteClient
from evernote.edam.notestore.ttypes import RelatedQuery, NoteFilter, NotesMetadataResultSpec
import requests
import sys
#SET THESE VALUES!!!
auth_token = "INSERT DEVELOPER TOKEN HERE"
notebook_name = "INSERT DESIRED NOTEBOOK NAME"
sandbox = "SET TO True (if on sandbox) or False (if on production)"
if auth_token == "INSERT DEVELOPER TOKEN HERE" or notebook_name == "INSERT DESIRED NOTEBOOK NAME" or sandbox == "SET TO True (if on sandbox) or False (if on production)":
print "Please specify values for \"auth_token\", \"notebook_name\", and \"sandbox\" in this file: %s." % sys.argv[0]
sys.exit(1)
#initialize the client, user and notestore
client=EvernoteClient(token=auth_token, sandbox=sandbox)
note_store=client.get_note_store()
user_store=client.get_user_store()
#get a list of personal notebooks
notebooks = note_store.listNotebooks()
#get the selected notebook
for notebook in notebooks:
if notebook.name == notebook_name:
selected_notebook = notebook
if not selected_notebook:
print "Could not find "
#return a list of metadata about the notes in the selected ntoebook.
noteFilter = NoteFilter()
noteFilter.notebookGuid = selected_notebook.guid
spec = NotesMetadataResultSpec()
spec.includeTitle = True
results = note_store.findNotesMetadata(noteFilter, 0, 100, spec)
#set the payload for the requests to get thumbnail
payload = {"auth":auth_token}
#set Base URL for thumbnail requests
if sandbox:
URL_BASE="https://sandbox.evernote.com/"
else:
URL_BASE="https://www.evernote.com/"
#get thumbnail for each note in the notebook
for note in results.notes:
#request for retriving the thumbnail
r=requests.post(URL_BASE+"shard/"+user_store.getUser().shardId+"/thm/note/"+note.guid+".jpg", data=payload)
if r.status_code == 200:
#if the request was successful write the thumbnail to disk
f = open(note.title+".jpg", 'w')
f.write(r.content)
f.close()
print "Wrote "+note.title+" thumbnail to disk."
else:
print "Error retriving thumbnail."
print "Returned " + r.status_code + " status code."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment