Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- 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:
- date = p.get('created_at')
- date = str(date)[:10]
- post = WordPressPost()
- post.slug = p['slug']
- post.content = p['markdown']
- post.title = p['title']
- post.post_status = 'publish'
- try:
- post.date = date
- except:
- print "cannot parse date: " + date
- continue
- wp.call(NewPost(post))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement