test-wp.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. # Use Wordpress account - not the mysql credentials
  11. # Todo: use scopus later !!!
  12. wp = Client('http://localhost/~kopmann/ufo2/xmlrpc.php', 'ufo', '$ipepdv$')
  13. #print wp.call(GetPosts())
  14. #print wp.call(GetUserInfo())
  15. # Todo: Set the date of the post according to the scopus date
  16. post = WordPressPost()
  17. post.title = 'My post 7' # put title of the publication here
  18. post.slug = 'DOIxxxxx7' # set the name of the post different to the title
  19. post.content = 'This is a more complete example post about XML-RPC (but still not comlete enough)'
  20. post.id = wp.call(NewPost(post)) # Creates a new post and returns the id!
  21. post.terms_names = {
  22. # 'post_tag': ['test', 'firstpost'], # what's that? I don't use it currently
  23. 'category': ['Publications', 'Reports'] # defined in WP + python script
  24. }
  25. # whoops, I forgot to publish it!
  26. post.post_status = 'publish' # alternative is draft here !
  27. post.comment_status = 'open' # allow comments - may be only for scopus
  28. wp.call(EditPost(post.id, post))# Update the before created post
  29. # Todo:
  30. # Save the id in the publication table, together with the with the scopus id
  31. # and bibtext file
  32. # Create a table with the defined authors and their publications?! (later)
  33. # Todo
  34. # - try to add a comment to a post !!!
  35. # - how to identify that a post has been deleted, because the publication
  36. # does not fit to the scope of the site? E.g. the Auger publications?
  37. # or my biotech items???
  38. #
  39. comment = WordPressComment()
  40. comment.content = 'Hi, thats cool - we can also add our comments automatically'
  41. comment.id = wp.call(NewComment(post.id, comment))