12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- # Test access to Wordpress
- #
- # Comment: Quite a usefull API to attach external scripts!!!
- #
- from wordpress_xmlrpc import Client
- from wordpress_xmlrpc import WordPressPost, WordPressComment
- from wordpress_xmlrpc.methods.posts import GetPosts, NewPost, EditPost
- from wordpress_xmlrpc.methods.comments import NewComment, EditComment
- from wordpress_xmlrpc.methods.users import GetUserInfo
- from wordpress_xmlrpc.methods.taxonomies import GetTerms
- from config import *
- def wordpress_get_category(slug):
- # Load taxonomy and search for the slug
- catlist = wp.call(GetTerms('category'))
- for cat in catlist:
- if cat.slug == slug:
- return cat
- # Use Wordpress account - not the mysql credentials
- # Todo: use scopus later !!!
- wp = Client(wp_api_url,wp_user,wp_password)
- #print wp.call(GetPosts())
- #print wp.call(GetUserInfo())
- # Test access to categories
- categories = []
- cat = wordpress_get_category("sensors")
- if cat:
- print "Found ", cat.name
- categories.append(cat)
- # Todo: Set the date of the post according to the scopus date
- post = WordPressPost()
- post.title = 'My post 7' # put title of the publication here
- post.slug = 'DOIxxxxx7' # set the name of the post different to the title
- post.content = 'This is a more complete example post about XML-RPC (but still not comlete enough)'
- #post.id = wp.call(NewPost(post)) # Creates a new post and returns the id!
- post.terms = categories
- post.terms_names = {
- #'post_tag': ['test', 'firstpost'], # what's that? I don't use it currently
- 'category': ['Publications', 'asics'] # defined in WP + python script
- }
- # whoops, I forgot to publish it!
- post.post_status = 'publish' # alternative is draft here !
- post.comment_status = 'open' # allow comments - may be only for scopus
- post.id = wp.call(NewPost(post)) # Creates a new post and returns the id!
- #wp.call(EditPost(post.id, post))# Update the before created post
- print "Created Wordpress post ", post.id
- # Todo:
- # Save the id in the publication table, together with the with the scopus id
- # and bibtext file
- # Create a table with the defined authors and their publications?! (later)
- # Todo
- # - try to add a comment to a post !!!
- # - how to identify that a post has been deleted, because the publication
- # does not fit to the scope of the site? E.g. the Auger publications?
- # or my biotech items???
- #
- #comment = WordPressComment()
- #comment.content = 'Hi, thats cool - we can also add our comments automatically'
- #comment.id = wp.call(NewComment(post.id, comment))
|