-
Notifications
You must be signed in to change notification settings - Fork 4
/
inspect_dois.py
52 lines (40 loc) · 1.47 KB
/
inspect_dois.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import requests
import math
from progressbar import progressbar
from caltechdata_api import caltechdata_edit
def fix_name(metadata, fixed):
for name in metadata:
if name["nameType"] == "Personal":
if "givenName" not in name:
fixed = True
given = name["name"].split(",")[1]
name["givenName"] = given.strip()
return metadata, fixed
url = 'https://data.caltech.edu/api/records?q=-metadata.related_identifiers.identifier%3A"10.25989%2Fes8t-kswe"'
headers = {
"accept": "application/vnd.datacite.datacite+json",
}
response = requests.get(f"{url}&search_type=scan&scroll=5m")
total = response.json()["hits"]["total"]
pages = math.ceil(int(total) / 1000)
hits = []
print(total)
for c in progressbar(range(1, pages + 1)):
chunkurl = f"{url}&sort=newest&size=1000&page={c}"
response = requests.get(chunkurl)
response = response.json()
hits += response["hits"]["hits"]
url = "https://data.caltech.edu/api/records"
for h in progressbar(hits):
idv = str(h["id"])
doi = h["pids"]["doi"]
if "client" not in doi:
if "10.22002/" in doi["identifier"]:
response = requests.get(f"{url}/{idv}", headers=headers)
if response.status_code != 200:
print(response.text)
exit()
else:
metadata = response.json()
print(idv)
caltechdata_edit(idv, metadata, production=True, publish=True)