EmmaScharfmannBerkeley commited on
Commit
a1275d0
·
1 Parent(s): fa9d5b7

Update Climate_site/python_scripts/related_scientist.py

Browse files
Climate_site/python_scripts/related_scientist.py CHANGED
@@ -276,70 +276,73 @@ def from_author_id(main_author_ids, year, country_code , size):
276
 
277
  url = "https://api.openalex.org/works?filter=author.id:" + main_author_id + ",publication_year:>" + str(year) + "&per_page=200&mailto=emma_scharfmann@berkeley.edu"
278
 
279
- data = get_data(url)["results"]
280
-
281
- for k in tqdm(range(len(data))):
282
- work_id = data[k]["id"][21:]
283
- for j in range(len(data[k]["authorships"])):
284
- author_id = data[k]["authorships"][j]["author"]["id"][21:]
285
-
286
- if author_id != main_author_id:
287
- if author_id not in dic_main_workers:
288
- dic_main_workers[author_id] = {}
289
- dic_main_workers[author_id]["author_name"] = data[k]["authorships"][j]["author"]["display_name"]
290
- dic_main_workers[author_id]["co_authors"] = 0
291
- dic_main_workers[author_id]["citations"] = 0
292
- dic_main_workers[author_id]["institution"] = None
293
- dic_main_workers[author_id]["country_code"] = None
294
- dic_main_workers[author_id]["id"] = None
295
- dic_main_workers[author_id]["longitude"] = None
296
- dic_main_workers[author_id]["latitude"] = None
297
-
298
- if dic_main_workers[author_id]["institution"] == None and data[k]["authorships"][j]["institutions"] != [] and "display_name" in data[k]["authorships"][j]["institutions"][0]:
299
- dic_main_workers[author_id]["institution"] = data[k]["authorships"][j]["institutions"][0]["display_name"]
300
- if dic_main_workers[author_id]["country_code"] == None and data[k]["authorships"][j]["institutions"] != [] and "country_code" in data[k]["authorships"][j]["institutions"][0]:
301
- dic_main_workers[author_id]["country_code"] = data[k]["authorships"][j]["institutions"][0]["country_code"]
302
- if dic_main_workers[author_id]["id"] == None and data[k]["authorships"][j]["institutions"] != [] and "id" in data[k]["authorships"][j]["institutions"][0] and data[k]["authorships"][j]["institutions"][0]["id"] != None:
303
- dic_main_workers[author_id]["id"] = data[k]["authorships"][j]["institutions"][0]["id"][21:]
304
-
305
-
306
-
307
- dic_main_workers[author_id]["co_authors"] += 1
308
-
309
- url = "https://api.openalex.org/works?filter=referenced_works:" + work_id + ",publication_year:>" + str(year) + "&per_page=200&mailto=emma_scharfmann@berkeley.edu"
310
-
311
-
312
 
313
- citations_data = get_data(url)["results"]
314
- for i in range(len(citations_data)):
315
- citing_work_id = citations_data[i]["id"][21:]
316
- for j in range(len(citations_data[i]["authorships"])):
317
- citing_author_id = citations_data[i]["authorships"][j]["author"]["id"][21:]
318
-
319
- if citing_author_id != main_author_id:
320
- if citing_author_id not in dic_main_workers:
321
- dic_main_workers[citing_author_id] = {}
322
- dic_main_workers[citing_author_id]["author_name"] = citations_data[i]["authorships"][j]["author"]["display_name"]
323
- dic_main_workers[citing_author_id]["co_authors"] = 0
324
- dic_main_workers[citing_author_id]["citations"] = 0
325
- dic_main_workers[citing_author_id]["institution"] = None
326
- dic_main_workers[citing_author_id]["country_code"] = None
327
- dic_main_workers[citing_author_id]["id"] = None
328
- dic_main_workers[citing_author_id]["longitude"] = None
329
- dic_main_workers[citing_author_id]["latitude"] = None
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
330
 
331
- if dic_main_workers[citing_author_id]["institution"] == None and (citations_data[i]["authorships"][j]["institutions"] != [] and "display_name" in citations_data[i]["authorships"][j]["institutions"][0]):
332
- dic_main_workers[citing_author_id]["institution"] = citations_data[i]["authorships"][j]["institutions"][0]["display_name"]
333
- if dic_main_workers[citing_author_id]["country_code"] == None and (citations_data[i]["authorships"][j]["institutions"] != [] and "country_code" in citations_data[i]["authorships"][j]["institutions"][0] ):
334
- dic_main_workers[citing_author_id]["country_code"] = citations_data[i]["authorships"][j]["institutions"][0]["country_code"]
335
- if dic_main_workers[citing_author_id]["id"] == None and ( citations_data[i]["authorships"][j]["institutions"] != [] and "id" in citations_data[i]["authorships"][j]["institutions"][0] and citations_data[i]["authorships"][j]["institutions"][0]["id"] != None):
336
- dic_main_workers[citing_author_id]["id"] = citations_data[i]["authorships"][j]["institutions"][0]["id"][21:]
337
-
338
-
339
-
340
- dic_main_workers[citing_author_id]["citations"] += 1
341
-
342
-
343
  for author_id in dic_main_workers:
344
  if dic_main_workers[author_id]["id"] != None:
345
  institution_id = dic_main_workers[author_id]["id"]
 
276
 
277
  url = "https://api.openalex.org/works?filter=author.id:" + main_author_id + ",publication_year:>" + str(year) + "&per_page=200&mailto=emma_scharfmann@berkeley.edu"
278
 
279
+ try:
280
+ data = get_data(url)["results"]
281
+
282
+ for k in tqdm(range(len(data))):
283
+ work_id = data[k]["id"][21:]
284
+ for j in range(len(data[k]["authorships"])):
285
+ author_id = data[k]["authorships"][j]["author"]["id"][21:]
286
+
287
+ if author_id != main_author_id:
288
+ if author_id not in dic_main_workers:
289
+ dic_main_workers[author_id] = {}
290
+ dic_main_workers[author_id]["author_name"] = data[k]["authorships"][j]["author"]["display_name"]
291
+ dic_main_workers[author_id]["co_authors"] = 0
292
+ dic_main_workers[author_id]["citations"] = 0
293
+ dic_main_workers[author_id]["institution"] = None
294
+ dic_main_workers[author_id]["country_code"] = None
295
+ dic_main_workers[author_id]["id"] = None
296
+ dic_main_workers[author_id]["longitude"] = None
297
+ dic_main_workers[author_id]["latitude"] = None
298
+
299
+ if dic_main_workers[author_id]["institution"] == None and data[k]["authorships"][j]["institutions"] != [] and "display_name" in data[k]["authorships"][j]["institutions"][0]:
300
+ dic_main_workers[author_id]["institution"] = data[k]["authorships"][j]["institutions"][0]["display_name"]
301
+ if dic_main_workers[author_id]["country_code"] == None and data[k]["authorships"][j]["institutions"] != [] and "country_code" in data[k]["authorships"][j]["institutions"][0]:
302
+ dic_main_workers[author_id]["country_code"] = data[k]["authorships"][j]["institutions"][0]["country_code"]
303
+ if dic_main_workers[author_id]["id"] == None and data[k]["authorships"][j]["institutions"] != [] and "id" in data[k]["authorships"][j]["institutions"][0] and data[k]["authorships"][j]["institutions"][0]["id"] != None:
304
+ dic_main_workers[author_id]["id"] = data[k]["authorships"][j]["institutions"][0]["id"][21:]
305
+
306
+
307
+
308
+ dic_main_workers[author_id]["co_authors"] += 1
309
+
310
+ url = "https://api.openalex.org/works?filter=referenced_works:" + work_id + ",publication_year:>" + str(year) + "&per_page=200&mailto=emma_scharfmann@berkeley.edu"
 
311
 
312
+
313
+ try:
314
+ citations_data = get_data(url)["results"]
315
+ for i in range(len(citations_data)):
316
+ citing_work_id = citations_data[i]["id"][21:]
317
+ for j in range(len(citations_data[i]["authorships"])):
318
+ citing_author_id = citations_data[i]["authorships"][j]["author"]["id"][21:]
319
+
320
+ if citing_author_id != main_author_id:
321
+ if citing_author_id not in dic_main_workers:
322
+ dic_main_workers[citing_author_id] = {}
323
+ dic_main_workers[citing_author_id]["author_name"] = citations_data[i]["authorships"][j]["author"]["display_name"]
324
+ dic_main_workers[citing_author_id]["co_authors"] = 0
325
+ dic_main_workers[citing_author_id]["citations"] = 0
326
+ dic_main_workers[citing_author_id]["institution"] = None
327
+ dic_main_workers[citing_author_id]["country_code"] = None
328
+ dic_main_workers[citing_author_id]["id"] = None
329
+ dic_main_workers[citing_author_id]["longitude"] = None
330
+ dic_main_workers[citing_author_id]["latitude"] = None
331
+
332
+ if dic_main_workers[citing_author_id]["institution"] == None and (citations_data[i]["authorships"][j]["institutions"] != [] and "display_name" in citations_data[i]["authorships"][j]["institutions"][0]):
333
+ dic_main_workers[citing_author_id]["institution"] = citations_data[i]["authorships"][j]["institutions"][0]["display_name"]
334
+ if dic_main_workers[citing_author_id]["country_code"] == None and (citations_data[i]["authorships"][j]["institutions"] != [] and "country_code" in citations_data[i]["authorships"][j]["institutions"][0] ):
335
+ dic_main_workers[citing_author_id]["country_code"] = citations_data[i]["authorships"][j]["institutions"][0]["country_code"]
336
+ if dic_main_workers[citing_author_id]["id"] == None and ( citations_data[i]["authorships"][j]["institutions"] != [] and "id" in citations_data[i]["authorships"][j]["institutions"][0] and citations_data[i]["authorships"][j]["institutions"][0]["id"] != None):
337
+ dic_main_workers[citing_author_id]["id"] = citations_data[i]["authorships"][j]["institutions"][0]["id"][21:]
338
+
339
+ dic_main_workers[citing_author_id]["citations"] += 1
340
+
341
+ except:
342
+ pass
343
+ except:
344
+ pass
345
 
 
 
 
 
 
 
 
 
 
 
 
 
346
  for author_id in dic_main_workers:
347
  if dic_main_workers[author_id]["id"] != None:
348
  institution_id = dic_main_workers[author_id]["id"]