Created
August 20, 2018 10:59
-
-
Save haowen-xu/7556020ca4d4fe6592a5da3ec1fbd2e3 to your computer and use it in GitHub Desktop.
Import WordPress posts into DayOne
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
#!/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