Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Migrate Ghost to Wordpress
"""
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
xmlrpc_endpoint = ''
username = ''
password = ''
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)
if date is None:
p.get('created_at')
post = WordPressPost()
post.slug = p['slug']
post.content = p['html']
post.title = p['title']
post.post_status = 'publish'
try:
post.date = parse(date)
except:
continue
wp.call(NewPost(post))
@adlerdias

This comment has been minimized.

Copy link

commented Oct 1, 2015

I had to change:

for p in data['db'][0]['data']['posts']:

to

for p in data['data']['posts']:

Thanks, it saves me a lot of time

@eidmantas

This comment has been minimized.

Copy link

commented May 26, 2016

Hey @tzangms, I used your script, edited a bit and wrote a small blog post( http://www.eidmantas.com/how-to-migrate-from-ghost-to-wordpress/ ) , since I just needed to do a migration. I hope that's okay with you! TYVM for the help, it helped a lot.

Too bad I don't have time study JSON outputs of different Ghost versions, I bypassed stuff with except: exit for the time being. Creation date info was lost.

@kstrauser

This comment has been minimized.

Copy link

commented May 1, 2017

Thanks for this! I modified it a little to copy tags, too.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.