Skip to content

Instantly share code, notes, and snippets.

@haowen-xu
Created August 20, 2018 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save haowen-xu/7556020ca4d4fe6592a5da3ec1fbd2e3 to your computer and use it in GitHub Desktop.
Save haowen-xu/7556020ca4d4fe6592a5da3ec1fbd2e3 to your computer and use it in GitHub Desktop.
Import WordPress posts into DayOne
#!/usr/bin/env python
import subprocess
from xml.etree import ElementTree
tree = ElementTree.parse('wordpress.xml')
namespaces = {
'content': 'http://purl.org/rss/1.0/modules/content/',
'wp': 'http://wordpress.org/export/1.2/',
}
for item in tree.findall('channel/item'):
doc = {
'title': item.find('title').text,
'date': item.find('wp:post_date', namespaces).text,
'content': item.find('content:encoded', namespaces).text,
}
input_str = doc['title'] + '\n\n' + doc['content']
input_bytes = input_str.encode('utf-8')
args = [
'dayone2',
'-d', doc['date'],
'-z', 'Asia/Shanghai',
'new'
]
subprocess.run(args, input=input_bytes, check=True)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment