Browse Source

Fix configuration to use now slugs instead of real dispalyed names

Andreas Kopmann 5 years ago
parent
commit
1d335367ec
3 changed files with 56 additions and 36 deletions
  1. 40 30
      ak_wordpress.py
  2. 6 6
      etc/config_ufo_kit_edu.py
  3. 10 0
      log/scopus-publications-ufo-kit-edu.log

+ 40 - 30
ak_wordpress.py

@@ -82,78 +82,88 @@ def wordpress_post_by_scopus(data, category = []):
 
     # define post structure
     post = WordPressPost()
-    post.title = coredata['dc:title'].encode('utf-8')
+    post.title = coredata['dc:title']
     post.date = ts
 
     # 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:
-        post.excerpt += " et al."
+        post.excerpt += u' et al.'
     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:
-        post.excerpt += u', ' + coredata['prism:volume'].encode('utf-8')
+        post.excerpt += u', ' + coredata['prism:volume']
     post.excerpt += u' (' + str(year).encode('utf-8') + u')'
     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:
-        post.excerpt += u', ' + coredata['article-number'].encode('utf-8')
+        post.excerpt += u', ' + coredata['article-number']
     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)
     if len(authors) > 20:
-        post.content += " et al."
+        post.content += u' et al.'
     else:
         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>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:
-        post.content += u', ' + coredata['prism:volume'].encode('utf-8')
+        post.content += u', ' + coredata['prism:volume']
     post.content += u' (' + str(year).encode('utf-8') + u')'
     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:
-        post.content += u', ' + coredata['article-number'].encode('utf-8')
+        post.content += u', ' + coredata['article-number']
     post.content += u'.'
     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'
     if 'dc:description' in coredata:
         post.content += u'<div class="accordion-inner"><h4>Abstract</h4>' + coredata['dc:description']
         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>'
     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>'
 
     #print post.content
-
     #post.id = wp.call(NewPost(post)) # Creates a new post and returns the id!
 
     catlist = []
     for slug in category:
-        cat = wordpress_get_category(slug)
-        catlist.append(cat)
+        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:
-        taglist = []
         for tag in data['abstracts-retrieval-response']['authkeywords']['author-keyword']:
-            print "Keyword: ", tag
-            taglist.append(tag['$'])
+            try:
+                print "Keyword: ", tag
+                taglist.append(tag['$'].decode('utf-8','ignore'))
+            except:
+                print "Keyword contains special characters - droped!"
+                pass
     except:
-        pass
+        # No keywords given
+	pass
 
     post.terms_names = {
-            'category': ['Publications'],
-            'post_tag': taglist
-        }
+        'category': ['Publications'],
+        'post_tag': taglist
+    }
+    print post.terms_names
 
     # whoops, I forgot to publish it!
     if len(authors) > sc_max_authors:
@@ -166,7 +176,7 @@ def wordpress_post_by_scopus(data, category = []):
     # 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 !!!
     return post.id

+ 6 - 6
etc/config_ufo_kit_edu.py

@@ -78,7 +78,7 @@ michaelHeethoff = "55979397800"
 sebastianSchmelzle = "34768986100"
 
 # UHD, has been combined with another person in Munich !!!
-philipLoesel = "57190622016"
+philipLoesel = "57203423658"
 
 # Others (e.g. for black list)
 ashotChiligarian = "7004126133"
@@ -101,11 +101,11 @@ ufo_apps = [thomasVandekamp]
 ufo_alg = [philipLoesel]
 
 sc_workgroups = [
-{'name':"Computing",'authors':ufo_pdv},
-{'name':"Electronics",'authors':ufo_eps},
-{'name':"X-ray Imaging",'authors':ufo_ips},
-{'name':"Morphology",'authors':ufo_apps},
-#{'name':"Algorithms",'authors':ufo_alg}
+{'name':'computing','authors':ufo_pdv},
+{'name':'electronics','authors':ufo_eps},
+{'name':'x-ray-imaging','authors':ufo_ips},
+{'name':'morphology','authors':ufo_apps},
+{'name':'algorithms','authors':ufo_alg}
 ]
 """ Definition of the workgroups
     

+ 10 - 0
log/scopus-publications-ufo-kit-edu.log

@@ -65,3 +65,13 @@ scopus-get-publications.py
 2018-08-02	14:57:31	  171	    4	     	     	0:00:22.646739
 2018-09-13	11:51:45	  175	    2	     	     	0:00:20.734607
 2018-10-24	17:55:23	  177	    3	     	     	0:00:22.608117
+2018-11-18	23:32:23	  183	    2	     	     	0:00:16.469450
+2018-11-19	09:06:09	  183	    2	     	     	0:00:18.915039
+2018-11-19	09:09:53	  185	    0	     	     	0:00:15.178698
+2018-11-19	09:18:01	  183	    2	     	     	0:00:18.858278
+2018-11-19	09:40:11	  183	    2	     	     	0:00:20.500910
+2018-11-19	09:41:27	  183	    2	     	     	0:00:18.911137
+2018-11-19	09:49:00	  183	    2	     	     	0:00:18.318267
+2018-11-19	10:02:09	  183	    2	     	     	0:00:18.999183
+2018-11-19	10:14:01	  183	    2	     	     	0:00:27.101883
+2018-11-19	11:03:17	  185	    2	     	     	0:00:23.241898