Last active
October 6, 2017 10:04
Star
You must be signed in to star a gist
Proof of concept Wordpress.com to Ghost.org converter
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/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