Browse Source

Move counting of publication from update_citations to update_publications

Andreas Kopmann 5 years ago
parent
commit
331c932c71
1 changed files with 20 additions and 11 deletions
  1. 20 11
      scopus_get_publications.py

+ 20 - 11
scopus_get_publications.py

@@ -129,9 +129,6 @@ def update_publications(authids,authname='',scopus_opts = '',max=0):
 def update_citations():
     """ Read all citations and store in the citation table """
 
-
-    global npubs
-    
     print ""
     print "=== Update citatation of all publication in the database"
     
@@ -147,10 +144,6 @@ def update_citations():
             sql = "SELECT wpid,eid,citedbycount,citesloaded FROM publications WHERE wpid > 0"
             cursor.execute(sql)
             result = cursor.fetchall()
-          
-            print "Total number of publications is %d" % len(result)
-            npubs = len(result)
-            #print "Npubs = %d" % npubs
 
             for pub in result:
                 wpid = int(pub['wpid'])
@@ -208,7 +201,7 @@ def update_citations():
 def update_wp_posts():
     """ Create wordpress posts for all entries that have none """
 
-
+    global npubs
     global nnewpubs
 
     print ""
@@ -221,6 +214,15 @@ def update_wp_posts():
     # Todo: Shift to a separate script !?
     try:
         with connection.cursor() as cursor:
+            # Read a single record
+            sql = "SELECT wpid,eid,citedbycount,citesloaded FROM publications WHERE wpid > 0"
+            cursor.execute(sql)
+            result = cursor.fetchall()
+
+            print "Total number of publications is %d" % len(result)
+            npubs = len(result)
+            #print "Npubs = %d" % npubs
+
             # Count all publications
             #sql = "SELECT COUNT(id) FROM publications"
             #cursor.execute(sql)
@@ -383,8 +385,9 @@ if __name__ == "__main__":
     print "Date       = " + str(start)
     print "NPubs      = " + str(npubs)
     print "NNewPubs   = " + str(nnewpubs)
-    print "NCites     = " + str(ncites)
-    print "NNewCites  = " + str(nnewcites)
+    if sc_citations:
+        print "NCites     = " + str(ncites)
+        print "NNewCites  = " + str(nnewcites)
     print "Runtime    = " + str(end - start)
 
 
@@ -401,9 +404,15 @@ if __name__ == "__main__":
 
 
     log = open(log_file,"a")
-    log.write("%s\t%s\t%5d\t%5d\t%5d\t%5d\t%s\n" % (start.strftime("%Y-%m-%d"),
+    if sc_citations:
+        log.write("%s\t%s\t%5d\t%5d\t%5d\t%5d\t%s\n" % (start.strftime("%Y-%m-%d"),
                                         start.strftime("%H:%M:%S"),
                                         npubs,nnewpubs,ncites,nnewcites,str(end-start)))
+    else:
+        log.write("%s\t%s\t%5d\t%5d\t%5s\t%5s\t%s\n" % (start.strftime("%Y-%m-%d"),
+                                        start.strftime("%H:%M:%S"),
+                                        npubs,nnewpubs,"","",str(end-start)))
+
     log.close()
 
     # done