-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbuild-data.py
36 lines (33 loc) · 1.47 KB
/
build-data.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import requests
headers = {
"Content-Type": "application/json"
}
params = {
"format": "json",
"resulttype": "core"
}
EUROPE_PMC = "https://www.ebi.ac.uk/europepmc/webservices/rest/search/query=ext_id:PMID%20src:med&resulttype=core&format=json"
PMID_SET = ["38863274", "38935577", "38863299", "38895901", "38950402", "38127458", "38932980", "38926517", "38924012", "36111857", "34878104", "33167871"]
for id in PMID_SET:
new_url = EUROPE_PMC.replace("PMID", id)
# print(new_url)
res = requests.get(url=new_url, headers=headers)
json_data = None
if res.status_code == 200:
json_data = res.json()
if json_data is not None:
# print(json.dumps(json_data))
author_list = json_data["resultList"]["result"][0]["authorList"]["author"]
for author in author_list:
first_name = author["firstName"]
last_name = author["lastName"]
if "authorAffiliationDetailsList" in author:
affiliations = author['authorAffiliationDetailsList']['authorAffiliation']
aff1 = affiliations[0]["affiliation"]
aff2 = None
if len(affiliations) >= 2:
aff2 = affiliations[1]["affiliation"]
if aff2 is not None:
print(first_name + "\t" + last_name + "\t" + "[email protected]\t" + aff1 + "\t" + aff2)
else:
print(first_name + "\t" + last_name + "\t" + "[email protected]\t" + aff1)