Guest User

Untitled

a guest
May 6th, 2018
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.68 KB | None | 0 0
  1. entry_points={
  2. 'console_scripts':
  3. ['update = dnurt_integration.program:update']
  4. }
  5.  
  6. $ update
  7.  
  8. No such file or directory: 'dnurt_integration/dnurtdb/dbconfig.json'
  9.  
  10. from os import system
  11.  
  12. from dnurt_integration.scopus import client as sc_client
  13. from dnurt_integration.web_of_science import client as w_client
  14. from dnurt_integration.gooscholar import client as g_client
  15.  
  16.  
  17. def update():
  18. system('clear')
  19. arg = None
  20. if sys.argv[1]:
  21. arg = sys.argv[1]
  22.  
  23. if arg == '-s':
  24. update_scopus()
  25. elif arg == '-g':
  26. update_gscholar()
  27. elif arg == '-w':
  28. update_wos()
  29. else:
  30. update_all()
  31.  
  32.  
  33. def update_scopus():
  34. print('Updating scopus info...')
  35. sc_client.update_db()
  36. print('Done.')
  37.  
  38.  
  39. def update_all():
  40. update_scopus()
  41. update_gscholar()
  42. update_wos()
  43.  
  44.  
  45. def update_gscholar():
  46. print('Updating gscholar info...')
  47. # g_client.update_db()
  48. print('Done.')
  49.  
  50.  
  51. def update_wos():
  52. print('Updating wos info...')
  53. # w_client.update_db()
  54. print('Done.')
  55.  
  56.  
  57. if __name__ == '__main__':
  58. update()
  59.  
  60. db_conf = open("dnurt_integration/dnurtdb/dbconfig.json")
  61. db_config = json.load(db_conf)
  62. db_conf.close()
  63.  
  64. connect_str = "dbname={0} user={1} password={2}"
  65. .format(db_config['dbname'], db_config['user'], db_config['password'])
  66.  
  67. conn = None
  68.  
  69. tables = ('authors',)
  70. columns = ('id', 'fullname', 'cited_by_count',
  71. 'citation_count', 'sc_id', 'hirsha', 'doc_count')
  72.  
  73.  
  74. def connect():
  75. global conn
  76.  
  77. try:
  78. conn = psycopg2.connect(connect_str)
  79. return True
  80. except psycopg2.DatabaseError as e:
  81. print('Error: db connect()', e)
  82. return False
  83.  
  84.  
  85. def get_cursor():
  86. return conn.cursor()
  87.  
  88.  
  89. def disconnect():
  90. global is_connected
  91. try:
  92. conn.close()
  93. is_connected = False
  94. except:
  95. print('Error: db connection close()')
  96.  
  97.  
  98. def get_author_ids():
  99. if connect():
  100. cursor = get_cursor()
  101. cursor.execute("""select {0} from {1}""".format(columns[4], tables[0]))
  102. ids = []
  103. for id in cursor.fetchall():
  104. ids.append(id[0])
  105. return ids
  106.  
  107.  
  108. def scopus_update(author):
  109. if connect():
  110. cursor = get_cursor()
  111. cursor.execute("""update {0} set {1}='{2}', {3}='{4}', {5}='{6}', {7}='{8}', {9}='{10}' where {11}='{12}'"""
  112. .format(tables[0], columns[1], author.fullname,
  113. columns[2], author.cited_by_count,
  114. columns[3], author.citation_count,
  115. columns[5], author.h_index,
  116. columns[6], author.doc_count,
  117. columns[4], author.sc_id))
  118. conn.commit()
Add Comment
Please, Sign In to add comment