Created
July 8, 2011 11:58
-
-
Save jplattel/1071682 to your computer and use it in GitHub Desktop.
Synchronize all your Kindle clippings and notes into Evernote
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
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) |
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?
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
OS X only as it uses Applescript for the interaction with Evernote.