Skip to content

Instantly share code, notes, and snippets.

@jplattel
Created July 8, 2011 11:58
Show Gist options
  • Star 21 You must be signed in to star a gist
  • Fork 8 You must be signed in to fork a gist
  • Save jplattel/1071682 to your computer and use it in GitHub Desktop.
Save jplattel/1071682 to your computer and use it in GitHub Desktop.
Synchronize all your Kindle clippings and notes into Evernote
import os
import time
document = open("My Clippings.txt","r")
data = "".join(document.readlines())
notes = []
try:
clippings = data.split('==========')
for clip in clippings:
clipping = clip.split('Added on ')
title = clipping[0].split('\r\n- ')[0].replace('\r\n','')
date = clipping[1].split('\r\n')[0]
location = clipping[0].split('\r\n- ')[1].replace('\r\n','')
text = clipping[1].split('\r\n\r\n')[1]
note = {'title': title, 'date': date, 'location': location, 'text': text}
notes.append(note)
#print note
except:
print 'Unable parse clipping'
def MakeEvernoteNote(note):
cmd = '''
osascript<<END
tell application "Evernote"
set clip to create note title "
'''+ unicode(note['title'], errors="ignore") + '''
" with text "
'''+ unicode(note['text'], errors="ignore") + "\n" + unicode(note['location'], errors="ignore") + unicode(note['date'], errors="ignore") + '''
"
if (not (tag named "Kindle" exists)) then
make tag with properties {name:"Kindle"}
end if
assign tag "Kindle" to clip
end tell
END'''
os.system(cmd)
for note in notes:
time.sleep(1)
MakeEvernoteNote(note)
@ryanwcohen
Copy link

Should this work in Windows, or do I need to use this on a *nix environment?

@jplattel
Copy link
Author

OS X only as it uses Applescript for the interaction with Evernote.

@ryanwcohen
Copy link

I tried running it on OS X 10.7, but I got the following errors until I killed it:

Unable parse clipping
612:615: execution error: Can’t get end. (-1728)
835:838: execution error: Can’t get end. (-1728)
1283:1286: execution error: Can’t get end. (-1728)
1590:1593: execution error: Can’t get end. (-1728)
796:799: execution error: Can’t get end. (-1728)
^CTraceback (most recent call last):
File "KindleEvernoteSync.py", line 43, in
time.sleep(1)
KeyboardInterrupt

Thoughts?

@ryanwcohen
Copy link

Amendment: It looks like the notes in Evernote were being created up until the point that I killed the process, even though I was getting errors returned in the command line. Looks like it's mostly functional (and awesome. Thanks for writing/sharing this.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment