Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
A script to upload Tistory backup XML file to Evernote. Developer token from Evernote required.
import re
import sys
from lxml import etree
from StringIO import StringIO
from evernote.edam.type import ttypes
from evernote.api.client import EvernoteClient
parser = etree.HTMLParser()
def convert_to_edml(text):
tree = etree.parse(StringIO(text), parser)
content = etree.tostring(tree.find('body'), encoding='unicode', method="xml")
content = re.sub(r'(\<\/?)body(\>)', r'\1en-note\2', content)
return content
def make_note(noteStore, noteTitle, noteBody, created, category, parentNotebookGuid):
noteBody = convert_to_edml(noteBody)
nBody = u"<?xml version=\"1.0\" encoding=\"UTF-8\"?>"
nBody += u"<!DOCTYPE en-note SYSTEM \"\">"
nBody += noteBody
ourNote = ttypes.Note()
ourNote.title = noteTitle.encode('utf-8')
ourNote.content = nBody.encode('utf-8')
ourNote.created = int(created) * 1000
ourNote.updated = ourNote.created
ourNote.tagNames = ['tistory']
if category:
if parentNotebookGuid:
ourNote.notebookGuid = parentNotebookGuid
note = noteStore.createNote(ourNote)
return note
dev_token = "developer token"
notebook_name = 'notebook_name'
def upload_blog(tistory_blog_xml):
client = EvernoteClient(token=dev_token, sandbox=False)
noteStore = client.get_note_store()
notebooks = noteStore.listNotebooks()
parent_notebook = [notebook for notebook in notebooks if == notebook_name][0]
post_id = 0
for post in blog_xml.findall('post'):
post_id = post.find('id').text
title = post.find('title').text
content = post.find('content').text
created = post.find('published').text
category = post.find('category').text
make_note(noteStore, title, content, created, category, parent_notebook.guid)
print("Error: " + str(post_id))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment