Skip to content

Instantly share code, notes, and snippets.

@kstrauser kstrauser/ghost2wp.py forked from tzangms/ghost2wp.py
Last active Aug 2, 2018

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)['db'][0]['data']
# Build the tags map
tags_by_id = {tag['id']: tag['name'] for tag in data['tags']}
posts_tags = {}
for pt in data['posts_tags']:
posts_tags.setdefault(pt['post_id'], []).append(tags_by_id[pt['tag_id']])
for p in 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.terms_names = {'post_tag': posts_tags[p['id']]}
except:
print('> Post {id} ("{title}") has no tags'.format(**p))
try:
post.date = parse(date)
except:
continue
wp.call(NewPost(post))
@psycholyzern

This comment has been minimized.

Copy link

psycholyzern commented Aug 2, 2018

How to get xmrpc endpoint

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.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.