-
-
Save hinaloe/3328d1601a38168d3a07 to your computer and use it in GitHub Desktop.
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
""" | |
Requirements: | |
* A Wordpress Blog | |
* Ghost export file (json). | |
* Python Packages: python-wordpress-xmlrpc | |
>>> pip install python-wordpress-xmlrpc | |
WARNING: | |
USE THIS AT YOUR OWN RISK. | |
If your have any questions, please comment here below. | |
""" | |
from wordpress_xmlrpc import Client, WordPressPost | |
from wordpress_xmlrpc.methods.posts import NewPost | |
from dateutil.parser import parse | |
from time import sleep | |
import json | |
import datetime | |
xmlrpc_endpoint = 'http://wocker.dev/xmlrpc.php' | |
username = 'admin' | |
password = 'admin' | |
wp = Client(xmlrpc_endpoint, username, password) | |
filename = 'ghost.export.json' | |
with open(filename) as f: | |
text = f.read() | |
data = json.loads(text) | |
for p in data['db'][0]['data']['posts']: | |
print p['title'] | |
date = p.get('published_at', None) | |
post = WordPressPost() | |
post.slug = p['slug'] | |
post.content = p['html'] | |
post.title = p['title'] | |
post.post_status = 'publish' | |
# draft post | |
if date is None: | |
date = p.get('created_at') | |
post.post_status = 'draft' | |
print date | |
post.date = datetime.datetime.fromtimestamp(date / 1e3) | |
wp.call(NewPost(post)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment