test-wp.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. # Test access to Wordpress
  2. #
  3. # Comment: Quite a usefull API to attach external scripts!!!
  4. #
  5. from wordpress_xmlrpc import Client
  6. from wordpress_xmlrpc import WordPressPost, WordPressComment
  7. from wordpress_xmlrpc.methods.posts import GetPosts, NewPost, EditPost
  8. from wordpress_xmlrpc.methods.comments import NewComment, EditComment
  9. from wordpress_xmlrpc.methods.users import GetUserInfo
  10. from wordpress_xmlrpc.methods.taxonomies import GetTerms
  11. from config import *
  12. def wordpress_get_category(slug):
  13. # Load taxonomy and search for the slug
  14. catlist = wp.call(GetTerms('category'))
  15. for cat in catlist:
  16. if cat.slug == slug:
  17. return cat
  18. # Use Wordpress account - not the mysql credentials
  19. # Todo: use scopus later !!!
  20. wp = Client(wp_api_url,wp_user,wp_password)
  21. #print wp.call(GetPosts())
  22. #print wp.call(GetUserInfo())
  23. # Test access to categories
  24. categories = []
  25. cat = wordpress_get_category("sensors")
  26. if cat:
  27. print "Found ", cat.name
  28. categories.append(cat)
  29. # Todo: Set the date of the post according to the scopus date
  30. post = WordPressPost()
  31. post.title = 'My post 7' # put title of the publication here
  32. post.slug = 'DOIxxxxx7' # set the name of the post different to the title
  33. post.content = 'This is a more complete example post about XML-RPC (but still not comlete enough)'
  34. #post.id = wp.call(NewPost(post)) # Creates a new post and returns the id!
  35. post.terms = categories
  36. post.terms_names = {
  37. #'post_tag': ['test', 'firstpost'], # what's that? I don't use it currently
  38. 'category': ['Publications', 'asics'] # defined in WP + python script
  39. }
  40. # whoops, I forgot to publish it!
  41. post.post_status = 'publish' # alternative is draft here !
  42. post.comment_status = 'open' # allow comments - may be only for scopus
  43. post.id = wp.call(NewPost(post)) # Creates a new post and returns the id!
  44. #wp.call(EditPost(post.id, post))# Update the before created post
  45. print "Created Wordpress post ", post.id
  46. # Todo:
  47. # Save the id in the publication table, together with the with the scopus id
  48. # and bibtext file
  49. # Create a table with the defined authors and their publications?! (later)
  50. # Todo
  51. # - try to add a comment to a post !!!
  52. # - how to identify that a post has been deleted, because the publication
  53. # does not fit to the scope of the site? E.g. the Auger publications?
  54. # or my biotech items???
  55. #
  56. #comment = WordPressComment()
  57. #comment.content = 'Hi, thats cool - we can also add our comments automatically'
  58. #comment.id = wp.call(NewComment(post.id, comment))