Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
# Uploads a text note to Evernote and shares it. Supports Markdown conversion to HTML.
# Link is printed to open in Chrome and stored in system clipboard
# Text is entered via input alert or third-party launcher
# From Drafts: pythonista://EvernoteTextShare?action=run&argv=[[title]]&argv=[[body]]
# Token is stored in Keychain, note is saved in default notebook
# Based on Brett Kelly's Python code:
# and Ole Zorn's demo scripts:
# Requires Evernote dev token:
import keychain
import clipboard
import console
import sys
# import token stored in Pythonista's keychain
auth_token = keychain.get_password('evernote','USERNAME')
# Construct URL. Replace "googlechromes://" with "safari-https://" if you want to open the note in Safari
EN_HOST = ""
EN_URL = "googlechromes://%s" % EN_HOST
numArgs = len(sys.argv)
# Count arguments, if less than 3 enter title and text manually. Use with apps like Drafts
# and Launch Center Pro
if numArgs < 3:
title = console.input_alert('Note Title', 'Enter the title of your note')
body = console.input_alert('Note Text', 'Enter the text of your note')
print "Text received from another app, processing..."
title = sys.argv[1]
body = sys.argv[2]
# Convert Markdown text to valid HTML
# Add or remove extras to your liking
from markdown2 import markdown
text = markdown(body, extras=['footnotes', 'header-ids'])
print "Generating note..."
import evernote.edam.userstore.constants as UserStoreConstants
import evernote.edam.type.ttypes as Types
from evernote.api.client import EvernoteClient
client = EvernoteClient(token=auth_token, sandbox=False)
note_store = client.get_note_store()
userStore = client.get_user_store()
note = Types.Note()
note.title = title
# Generate note content and upload
# The content of an Evernote note is represented using Evernote Markup
# Language (ENML). The full ENML specification can be found in the Evernote
# API Overview at
note.content = '<?xml version="1.0" encoding="UTF-8"?>'
note.content += '<!DOCTYPE en-note SYSTEM ' \
note.content += '<en-note>'
note.content += text
note.content += '</en-note>'
note.content = note.content.encode('utf-8') # assign the result to change original string
print "Uploading clip to Evernote..."
created_note = note_store.createNote(note)
noteGuid = created_note.guid
#Get user shardID and the note's unique share key
user = userStore.getUser(auth_token).shardId
shareKey = note_store.shareNote(auth_token, noteGuid)
print "Note URL set to clipboard. The note has been shared with the following URL:\n\n",
# Last, create two separate URLs for the browser you want to use
# and the link you want to share in the clipboard
final = "%s/shard/%s/sh/%s/%s" % \
(EN_URL, user, noteGuid, shareKey)
shareable = "%s/shard/%s/sh/%s/%s" % \
("", user, noteGuid, shareKey)
console.write_link(shareable, final)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment