-
-
Save noctella/fbe157885b8ff2e465a0 to your computer and use it in GitHub Desktop.
Send to Evernote Peek
This file contains 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
# This script takes the contents of the clipboard, in the format: | |
# Question | |
# Answer | |
# | |
# Question | |
# Answer | |
# | |
# ...and turns the questions into a series of individual notes in a new Evernote notebook of your | |
# choice.The title is the question, and the answer is the body of the note. You can import the notebook | |
# into Evernote peek to use as a series of flash cards. | |
# First you'll need a developer token. Visit | |
# https://www.evernote.com/api/DeveloperToken.action | |
# and copy the token there. | |
auth_token = "Your auth token" | |
# Then install the python Evernote sdk (make sure the script is in the directory 'evernote-sdk'. You can install it using the script: | |
# https://gist.github.com/5048588 | |
# Run this script from the root directory | |
import console | |
import sys | |
sys.path.append('evernote-sdk') | |
import clipboard | |
from io import BytesIO | |
import hashlib | |
import binascii | |
import traceback | |
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() | |
# Split the question/answer pairs | |
text = clipboard.get() | |
textLines = text.split('\n\n') | |
num_args = len(sys.argv) | |
# create a new notebook for the notes | |
notebook = Types.Notebook() | |
console.clear() | |
# If the script was called from a launcher, you can pass in the notebook name. Otherwise, prompt. | |
if num_args < 2: | |
notebook.name = console.input_alert('Study Pack Name', 'Enter the name of the Study Pack') | |
else: | |
print "Creating Study Pack '" + sys.argv[1] + "'" | |
notebook.name = sys.argv[1] | |
console.show_activity() | |
import markdown | |
notebook = note_store.createNotebook(notebook) | |
# create note for each question/answer | |
i = 0 | |
while i < len(textLines): | |
note = Types.Note() | |
textLines[i] = textLines[i].strip() | |
#Split the question/answer block into 2 parts | |
lines = textLines[i].split('\n', 1) | |
if len(lines) == 2: | |
# set the title (question) based on the first line of the question/answer | |
note.title = lines[0].strip() | |
note.title = note.title.encode('utf-8') | |
# set the body (answer) to the rest of the lines | |
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>' | |
text = markdown.markdown(lines[1]) | |
note.content += text | |
note.content += '</en-note>' | |
note.content = note.content.encode('utf-8', 'replace') # assign the result to change original string | |
note.notebookGuid = notebook.guid | |
note_store.createNote(note) | |
i = i + 1 | |
print "Done creating Study Pack!" | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment