Advertisement
Guest User

Untitled

a guest
Feb 1st, 2016
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.06 KB | None | 0 0
  1. """
  2. Requirements:
  3.  
  4. * A Wordpress Blog
  5. * Ghost export file (json).
  6. * Python Packages: python-wordpress-xmlrpc
  7.  
  8. >>> pip install python-wordpress-xmlrpc
  9.  
  10. WARNING:
  11.  
  12. USE THIS AT YOUR OWN RISK.
  13. If your have any questions, please comment here below.
  14.  
  15. """
  16.  
  17. from wordpress_xmlrpc import Client, WordPressPost
  18. from wordpress_xmlrpc.methods.posts import NewPost
  19.  
  20. from dateutil.parser import parse
  21. from time import sleep
  22. import json
  23.  
  24. xmlrpc_endpoint = ''
  25. username = ''
  26. password = ''
  27.  
  28. wp = Client(xmlrpc_endpoint, username, password)
  29.  
  30. filename = 'ghost.export.json'
  31.  
  32. with open(filename) as f:
  33. text = f.read()
  34.  
  35. data = json.loads(text)
  36.  
  37. for p in data['db'][0]['data']['posts']:
  38. print p['title']
  39.  
  40. date = p.get('published_at', None)
  41. if date is None:
  42. date = p.get('created_at')
  43. date = str(date)[:10]
  44.  
  45. post = WordPressPost()
  46. post.slug = p['slug']
  47. post.content = p['markdown']
  48. post.title = p['title']
  49. post.post_status = 'publish'
  50. try:
  51. post.date = date
  52. except:
  53. print "cannot parse date: " + date
  54. continue
  55.  
  56. wp.call(NewPost(post))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement