|
@@ -6,11 +6,13 @@
|
|
|
|
|
|
from datetime import datetime
|
|
from datetime import datetime
|
|
import json
|
|
import json
|
|
|
|
+from pprint import pprint
|
|
|
|
|
|
from wordpress_xmlrpc import Client
|
|
from wordpress_xmlrpc import Client
|
|
from wordpress_xmlrpc import WordPressPost, WordPressComment
|
|
from wordpress_xmlrpc import WordPressPost, WordPressComment
|
|
from wordpress_xmlrpc.methods.posts import GetPost, NewPost, EditPost
|
|
from wordpress_xmlrpc.methods.posts import GetPost, NewPost, EditPost
|
|
from wordpress_xmlrpc.methods.comments import NewComment, EditComment
|
|
from wordpress_xmlrpc.methods.comments import NewComment, EditComment
|
|
|
|
+from wordpress_xmlrpc.methods.taxonomies import GetTerms
|
|
|
|
|
|
from config import *
|
|
from config import *
|
|
|
|
|
|
@@ -18,6 +20,19 @@ from config import *
|
|
wp = Client(wp_api_url, wp_user, wp_password)
|
|
wp = Client(wp_api_url, wp_user, wp_password)
|
|
|
|
|
|
|
|
|
|
|
|
+#
|
|
|
|
+# Get category from slug name used in the configuration file
|
|
|
|
+#
|
|
|
|
+
|
|
|
|
+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
|
|
|
|
+
|
|
|
|
+
|
|
#
|
|
#
|
|
# query post
|
|
# query post
|
|
#
|
|
#
|
|
@@ -42,14 +57,19 @@ def wordpress_get_post(wpid):
|
|
#
|
|
#
|
|
def wordpress_post_by_scopus(data, category = []):
|
|
def wordpress_post_by_scopus(data, category = []):
|
|
""" Create a new post based on the Scopus information """
|
|
""" Create a new post based on the Scopus information """
|
|
|
|
+
|
|
|
|
+ #print data['abstracts-retrieval-response']
|
|
|
|
|
|
- coredata = data['abstracts-retrieval-response']['coredata']
|
|
|
|
try:
|
|
try:
|
|
|
|
+ coredata = data['abstracts-retrieval-response']['coredata']
|
|
authors = data['abstracts-retrieval-response']['authors']['author']
|
|
authors = data['abstracts-retrieval-response']['authors']['author']
|
|
|
|
+
|
|
except KeyError:
|
|
except KeyError:
|
|
|
|
+ pprint(data)
|
|
|
|
+ print ""
|
|
print "Have not found authors in dataset"
|
|
print "Have not found authors in dataset"
|
|
print " -> Is the connection to scopus broken???"
|
|
print " -> Is the connection to scopus broken???"
|
|
- exit()
|
|
|
|
|
|
+ return(0)
|
|
|
|
|
|
# decode date
|
|
# decode date
|
|
tsstring = coredata['prism:coverDate'].encode('utf-8')
|
|
tsstring = coredata['prism:coverDate'].encode('utf-8')
|
|
@@ -62,74 +82,102 @@ def wordpress_post_by_scopus(data, category = []):
|
|
|
|
|
|
# define post structure
|
|
# define post structure
|
|
post = WordPressPost()
|
|
post = WordPressPost()
|
|
- post.title = coredata['dc:title'].encode('utf-8')
|
|
|
|
|
|
+ post.title = coredata['dc:title']
|
|
post.date = ts
|
|
post.date = ts
|
|
|
|
|
|
# set the name of the post different to the title
|
|
# set the name of the post different to the title
|
|
- post.slug = coredata['dc:identifier'].encode('utf-8')
|
|
|
|
|
|
+ post.slug = coredata['dc:identifier']
|
|
|
|
|
|
- post.excerpt = authors[0]['ce:indexed-name'].encode('utf-8')
|
|
|
|
|
|
+ post.excerpt = authors[0]['ce:indexed-name']
|
|
if len(authors) > 2:
|
|
if len(authors) > 2:
|
|
- post.excerpt += " et al."
|
|
|
|
|
|
+ post.excerpt += u' et al.'
|
|
elif len(authors) == 2:
|
|
elif len(authors) == 2:
|
|
- post.excerpt += u', ' + authors[1]['ce:indexed-name'].encode('utf-8')
|
|
|
|
- post.excerpt += u', in <em>' + coredata['prism:publicationName'].encode('utf-8') + u'</em>'
|
|
|
|
|
|
+ post.excerpt += u', ' + authors[1]['ce:indexed-name']
|
|
|
|
+ post.excerpt += u', in <em>' + coredata['prism:publicationName'] + u'</em>'
|
|
if 'prism:volume' in coredata:
|
|
if 'prism:volume' in coredata:
|
|
- post.excerpt += u', ' + coredata['prism:volume'].encode('utf-8')
|
|
|
|
|
|
+ post.excerpt += u', ' + coredata['prism:volume']
|
|
post.excerpt += u' (' + str(year).encode('utf-8') + u')'
|
|
post.excerpt += u' (' + str(year).encode('utf-8') + u')'
|
|
if 'prism:pageRange' in coredata:
|
|
if 'prism:pageRange' in coredata:
|
|
- post.excerpt += u' ' + coredata['prism:pageRange'].encode('utf-8')
|
|
|
|
|
|
+ post.excerpt += u' ' + coredata['prism:pageRange']
|
|
if 'article-number' in coredata:
|
|
if 'article-number' in coredata:
|
|
- post.excerpt += u', ' + coredata['article-number'].encode('utf-8')
|
|
|
|
|
|
+ post.excerpt += u', ' + coredata['article-number']
|
|
post.excerpt += u'.'
|
|
post.excerpt += u'.'
|
|
|
|
|
|
- post.content = u'<p>' + authors[0]['ce:indexed-name'].encode('utf-8')
|
|
|
|
|
|
+ post.content = u'<p>' + authors[0]['ce:indexed-name']
|
|
authors.pop(0)
|
|
authors.pop(0)
|
|
if len(authors) > 20:
|
|
if len(authors) > 20:
|
|
- post.content += " et al."
|
|
|
|
|
|
+ post.content += u' et al.'
|
|
else:
|
|
else:
|
|
for author in authors:
|
|
for author in authors:
|
|
- post.content += u', ' + author['ce:indexed-name'].encode('utf-8')
|
|
|
|
|
|
+ post.content += u', ' + author['ce:indexed-name']
|
|
post.content += u'</p>'
|
|
post.content += u'</p>'
|
|
- post.content += u'<p>in <em>' + coredata['prism:publicationName'].encode('utf-8') + u'</em>'
|
|
|
|
|
|
+ post.content += u'<p>in <em>' + coredata['prism:publicationName'] + u'</em>'
|
|
if 'prism:volume' in coredata:
|
|
if 'prism:volume' in coredata:
|
|
- post.content += u', ' + coredata['prism:volume'].encode('utf-8')
|
|
|
|
|
|
+ post.content += u', ' + coredata['prism:volume']
|
|
post.content += u' (' + str(year).encode('utf-8') + u')'
|
|
post.content += u' (' + str(year).encode('utf-8') + u')'
|
|
if 'prism:pageRange' in coredata:
|
|
if 'prism:pageRange' in coredata:
|
|
- post.content += u' ' + coredata['prism:pageRange'].encode('utf-8')
|
|
|
|
|
|
+ post.content += u' ' + coredata['prism:pageRange']
|
|
if 'article-number' in coredata:
|
|
if 'article-number' in coredata:
|
|
- post.content += u', ' + coredata['article-number'].encode('utf-8')
|
|
|
|
|
|
+ post.content += u', ' + coredata['article-number']
|
|
post.content += u'.'
|
|
post.content += u'.'
|
|
if 'prism:doi' in coredata:
|
|
if 'prism:doi' in coredata:
|
|
- post.content += u' DOI:' + coredata['prism:doi'].encode('utf-8')
|
|
|
|
|
|
+ post.content += u' DOI:' + coredata['prism:doi']
|
|
post.content += u'</p>\n\n'
|
|
post.content += u'</p>\n\n'
|
|
if 'dc:description' in coredata:
|
|
if 'dc:description' in coredata:
|
|
post.content += u'<div class="accordion-inner"><h4>Abstract</h4>' + coredata['dc:description']
|
|
post.content += u'<div class="accordion-inner"><h4>Abstract</h4>' + coredata['dc:description']
|
|
if 'authkeywords' in coredata:
|
|
if 'authkeywords' in coredata:
|
|
- post.content += u'\n<b>Keywords:</b> ' + coredata['authkeywords'].encode('utf-8')
|
|
|
|
|
|
+ post.content += u'\n<b>Keywords:</b> ' + coredata['authkeywords']
|
|
post.content += u'</div>'
|
|
post.content += u'</div>'
|
|
if 'prism:doi' in coredata:
|
|
if 'prism:doi' in coredata:
|
|
- link = u'http://dx.doi.org/' + coredata['prism:doi'].encode('utf-8')
|
|
|
|
|
|
+ link = u'http://dx.doi.org/' + coredata['prism:doi']
|
|
post.content += u'\n\n<div class="accordion-inner"><a class="btn btn-primary" href="' + link + u'"><i class="icon-download icon-white"></i> Get it</a></div>'
|
|
post.content += u'\n\n<div class="accordion-inner"><a class="btn btn-primary" href="' + link + u'"><i class="icon-download icon-white"></i> Get it</a></div>'
|
|
|
|
|
|
#print post.content
|
|
#print post.content
|
|
|
|
+ #post.id = wp.call(NewPost(post)) # Creates a new post and returns the id!
|
|
|
|
+
|
|
|
|
+ catlist = []
|
|
|
|
+ for slug in category:
|
|
|
|
+ try:
|
|
|
|
+ cat = wordpress_get_category(slug)
|
|
|
|
+ catlist.append(cat)
|
|
|
|
+ except:
|
|
|
|
+ print "Slug %s not found in Wordpress" % slug
|
|
|
|
+ exit
|
|
|
|
+ post.terms = catlist
|
|
|
|
+ print post.terms
|
|
|
|
+
|
|
|
|
+ taglist = []
|
|
|
|
+ try:
|
|
|
|
+ for tag in data['abstracts-retrieval-response']['authkeywords']['author-keyword']:
|
|
|
|
+ try:
|
|
|
|
+ print "Keyword: ", tag
|
|
|
|
+ taglist.append(tag['$'].decode('utf-8','ignore'))
|
|
|
|
+ except:
|
|
|
|
+ print "Keyword contains special characters - droped!"
|
|
|
|
+ pass
|
|
|
|
+ except:
|
|
|
|
+ # No keywords given
|
|
|
|
+ pass
|
|
|
|
|
|
- post.id = wp.call(NewPost(post)) # Creates a new post and returns the id!
|
|
|
|
-
|
|
|
|
-
|
|
|
|
- if category == '':
|
|
|
|
- catlist = ['Publications']
|
|
|
|
- else:
|
|
|
|
- catlist = ['Publications'] + category
|
|
|
|
post.terms_names = {
|
|
post.terms_names = {
|
|
- 'category': catlist # defined in WP + python script
|
|
|
|
- }
|
|
|
|
|
|
+ 'category': ['Publications'],
|
|
|
|
+ 'post_tag': taglist
|
|
|
|
+ }
|
|
|
|
+ print post.terms_names
|
|
|
|
|
|
# whoops, I forgot to publish it!
|
|
# whoops, I forgot to publish it!
|
|
- post.post_status = 'publish' # alternative is draft here !
|
|
|
|
|
|
+ if len(authors) > sc_max_authors:
|
|
|
|
+ post.post_status = 'draft' # check how to handle publication in wordpress
|
|
|
|
+ print "Too many authors %d - set to draft" % (len(authors))
|
|
|
|
+ else:
|
|
|
|
+ post.post_status = 'publish' # handled as a standard publication
|
|
post.comment_status = 'closed' # allow comments - may be only for scopus
|
|
post.comment_status = 'closed' # allow comments - may be only for scopus
|
|
- wp.call(EditPost(post.id, post))# Update the before created post
|
|
|
|
|
|
|
|
|
|
+ # Todo: this can fail! Add proper error handling
|
|
|
|
+ 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 post.id
|
|
|
|
+
|
|
# need to update the database !!!
|
|
# need to update the database !!!
|
|
return post.id
|
|
return post.id
|
|
|
|
|