Editorial Workflows

HTML to Evernote

public workflow

Install Workflow...

This workflow contains at least one Python script. Only use it if you trust the person who shared this with you, and if you know exactly what it does.

I understand, install the workflow!

This is a workflow for Editorial, a Markdown and plain text editor for iOS. To download it, you need to view this page on a device that has the app installed.

Description: ::: Processes currently open text document.

::: Sends current document as an HTML note to the default Evernote folder. Escapes unicode as HTML escape strings.

Source: Macdrifter.com

Shared by: http://www.macdrifter.com/2013/08/password-handling-in-editorial-scripts.html

Comments: Comment Feed (RSS)

There are no comments yet.

+ Add Comment

Workflow Preview
Set Variable ?
Variable Name
title
Value
File Name
Run Python Script ?
Source Code
#coding: utf-8
import workflow
import webbrowser
import console
import keychain
import pickle
import evernote.edam.userstore.constants as UserStoreConstants
import evernote.edam.type.ttypes as Types
from evernote.api.client import EvernoteClient
import markdown2
import cgi
import editor

#keychain.delete_password('evernote', 'editorial')
login = keychain.get_password('evernote', 'editorial')
if login is not None:
	auth_token = pickle.loads(login)
else:
	token_choice = console.alert('Token Needed', 'A Developer Token is needed. Go get one?', 'Yes', 'I have One', 'Cancel')
	if token_choice == 1:
		webbrowser.open('safari-https://www.evernote.com/Login.action?targetUrl=%2Fapi%2FDeveloperToken.action')
		raise KeyboardInterrupt
	elif token_choice == 2:
		auth_token = console.password_alert('Evernote Developer Token', 'Paste Your Evernote Developer Token')
		pickle_token = pickle.dumps(auth_token)
		keychain.set_password('evernote', 'editorial', pickle_token)
	else:
		raise KeyboardInterrupt



current_text = editor.get_text()
doc_title = workflow.get_variable('title')
encode_string = cgi.escape(current_text).encode('ascii', 'xmlcharrefreplace')
html_text = markdown2.markdown(encode_string, extras=['fenced-code-blocks','smarty-pants', 'footnotes'])





client = EvernoteClient(token=auth_token, sandbox=False)
note_store = client.get_note_store()

notebooks = note_store.listNotebooks()


# To create a new note, simply create a new Note object and fill in
# attributes such as the note's title.
note = Types.Note()
note.title = doc_title

note.content = '<?xml version="1.0" encoding="UTF-8"?>'
note.content += '<!DOCTYPE en-note SYSTEM ' \
   '"http://xml.evernote.com/pub/enml2.dtd">'
note.content += '<en-note>' + html_text + '<br/>'
note.content += '</en-note>'

# Finally, send the new note to Evernote using the createNote method
# The new Note object that is returned will contain server-generated
# attributes such as the new note's unique GUID.
created_note = note_store.createNote(note)

#print "Successfully created a new note with GUID: ", created_note.guid

console.hud_alert(doc_title+' saved to the default folder in Evernote','success')