test-wp.py 1.9 KB

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