|
@@ -9,33 +9,59 @@ 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(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.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', 'Reports'] # defined in WP + python script
|
|
|
+ #'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
|
|
|
-wp.call(EditPost(post.id, post))# Update the before created post
|
|
|
+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
|
|
@@ -50,10 +76,10 @@ wp.call(EditPost(post.id, post))# Update the before created post
|
|
|
# or my biotech items???
|
|
|
#
|
|
|
|
|
|
-comment = WordPressComment()
|
|
|
-comment.content = 'Hi, thats cool - we can also add our comments automatically'
|
|
|
+#comment = WordPressComment()
|
|
|
+#comment.content = 'Hi, thats cool - we can also add our comments automatically'
|
|
|
|
|
|
-comment.id = wp.call(NewComment(post.id, comment))
|
|
|
+#comment.id = wp.call(NewComment(post.id, comment))
|
|
|
|
|
|
|
|
|
|