|
|
|
from evernote.api.client import NoteStore |
|
from evernote.api.client import EvernoteClient |
|
|
|
#Get your dev token from the following URL |
|
#https://www.evernote.com/api/DeveloperToken.action |
|
|
|
dev_token = "<your api token>" |
|
client = EvernoteClient(token=dev_token, sandbox=False) |
|
noteStore = client.get_note_store() |
|
|
|
|
|
filter = NoteStore.NoteFilter() |
|
|
|
#Find the guid of your catch notebook, by selecting the catch notebook and see the URL |
|
#https://www.evernote.com/Home.action#b=<guid> |
|
filter.notebookGuid = "<catch_notebook_guid>" |
|
|
|
spec = NoteStore.NotesMetadataResultSpec() |
|
spec.includeTitle = True |
|
spec.includeTagGuids = True |
|
|
|
index = 0 |
|
while True: |
|
noteList = noteStore.findNotesMetadata( dev_token, filter, index, 50, spec) |
|
for note in noteList.notes: |
|
index = index + 1 |
|
if (note.tagGuids != None and len(note.tagGuids) > 0): |
|
print "already tags present, so skipping...." |
|
print "--------------[" + str(index) + "]" |
|
continue |
|
|
|
note = noteStore.getNote(dev_token, note.guid, True, True, True, True) |
|
content = note.content |
|
print 'Title:', note.title, |
|
print 'Content:', content |
|
print "--------------[" + str(index) + "]" |
|
titlecontent = note.title + " " + content |
|
|
|
#Remove HTML tags |
|
titlecontent = re.sub('<[^<]+?>', ' ', titlecontent) |
|
|
|
#get tags |
|
tags = [word for word in titlecontent.split() if word.startswith('#') and len(word) > 1] |
|
|
|
#remove unwanted characters |
|
tags = [word.strip(" #;.,").lower() for word in tags ] |
|
tags = [word.split()[0] for word in tags if len(word.split()) > 0 ] |
|
tags = [word.strip(" #;.,") for word in tags if len(word.strip(" #;.,")) > 0 ] |
|
|
|
#remove duplicate tags |
|
tags_set = set(tags) |
|
tags = list(tags_set) |
|
|
|
#Add tags only if the actual note does not contain tags |
|
if len(tags) > 0 and (note.tagNames == None or len(note.tagNames) == 0): |
|
print "[" + str(index) + "]###########" + str(tags) |
|
note.tagNames = tags |
|
noteStore.updateNote(dev_token, note) |
|
|
|
if noteList.totalNotes <= index: |
|
break; |
|
print "FETCHING NEXT PAGE=======================" |
|
|
Check the blog for the steps
http://www.ramandv.com/blog/catch-com-to-evernote-migration/