Advertisement
Guest User

Untitled

a guest
Mar 14th, 2017
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 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['data']['posts']:
  38. print p['title']
  39.  
  40. date = p.get('published_at', None)
  41. if date is None:
  42. p.get('created_at')
  43.  
  44. post = WordPressPost()
  45. post.slug = p['slug']
  46. post.content = p['html']
  47. post.title = p['title']
  48. post.post_status = 'publish'
  49. try:
  50. post.date = parse(date)
  51. except:
  52. continue
  53.  
  54. wp.call(NewPost(post))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement