Skip to content

Instantly share code, notes, and snippets.

@mdornseif
Last active October 6, 2017 10:04
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save mdornseif/7dbd8998c4d019d5b361571a221240d9 to your computer and use it in GitHub Desktop.
Proof of concept Wordpress.com to Ghost.org converter
#!/usr/bin/python
# encoding: utf-8
# Proof of concept Wordpress.com to Ghost.org converter
import urlparse
from HTMLParser import HTMLParser
from ghost import Ghost # https://github.com/mdornseif/ghost-python
from markdownify import markdownify as md
from wordpress import API
wpapi = API(
url="https://public-api.wordpress.com",
# get at https://developer.wordpress.com/apps/
consumer_key="123",
consumer_secret="ABC",
api="", # wp-json
version="wp/v2",
wp_user="USER",
wp_pass="PASS"
)
h = HTMLParser()
g = Ghost('https://EXAMPLE.io/', '123')
status, body = g.authenticate('md@example.com', '123')
r = wpapi.get("/sites/EXAMPLE.wordpress.com/posts")
for post in r.json():
newpost = dict(
id = "%s" % post['id'], # Keep the Wordpress ID to avoid duplocates
url = urlparse.urlparse(post['link']).path, # convert absolute linn to local path
slug = post['slug'], # slug stays the same
)
title = h.unescape(post['title']['rendered']) # unescape HTML entities
content = md(post['content']['rendered']) # convert HTML to Markdown
status, body = g.post(title, 'published', content, **newpost) Create in Ghost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment