Skip to content

Commit 2a5302a

Browse files
committed
Additional metadata mapping fixes
1 parent 368b317 commit 2a5302a

File tree

1 file changed

+28
-20
lines changed

1 file changed

+28
-20
lines changed

caltechdata_api/customize_schema.py

Lines changed: 28 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,15 @@ def grid_to_ror(grid):
1515
ror = "00hm6j694"
1616
elif grid == "grid.5805.8":
1717
ror = "02en5vm52"
18+
elif grid == "grid.465477.3":
19+
ror = "00em52312"
1820
else:
1921
url = f"https://api.ror.org/organizations?query.advanced=external_ids.GRID.all:{grid}"
20-
results = requests.get(url)
21-
ror = results.json()["items"][0]["id"]
22+
results = requests.get(url).json()
23+
if len(results["items"]) == 0:
24+
print(url + "doesn't have a valid ROR")
25+
exit()
26+
ror = results["items"][0]["id"]
2227
ror = ror.split("ror.org/")[1]
2328
return ror
2429

@@ -177,24 +182,27 @@ def customize_schema_rdm(json_record):
177182
if additional != []:
178183
json_record["additional_titles"] = additional
179184

180-
descriptions = json_record.pop("descriptions")
181-
additional = []
182-
if len(descriptions) == 1:
183-
json_record["description"] = descriptions[0]["description"]
184-
else:
185-
for description in descriptions:
186-
if description["descriptionType"] == "Abstract":
187-
# If there are multiple Abstracts, extras will be lost
188-
json_record["description"] = description["description"]
189-
else:
190-
new = {}
191-
new["type"] = {"id": descriptiontypes[description["descriptionType"]]}
192-
new["description"] = description["description"]
193-
if "lang" in description:
194-
new["lang"] = {"id": description["lang"]}
195-
additional.append(new)
196-
if additional != []:
197-
json_record["additional_descriptions"] = additional
185+
if "descriptions" in json_record:
186+
descriptions = json_record.pop("descriptions")
187+
additional = []
188+
if len(descriptions) == 1:
189+
json_record["description"] = descriptions[0]["description"]
190+
else:
191+
for description in descriptions:
192+
if description["descriptionType"] == "Abstract":
193+
# If there are multiple Abstracts, extras will be lost
194+
json_record["description"] = description["description"]
195+
else:
196+
new = {}
197+
new["type"] = {
198+
"id": descriptiontypes[description["descriptionType"]]
199+
}
200+
new["description"] = description["description"]
201+
if "lang" in description:
202+
new["lang"] = {"id": description["lang"]}
203+
additional.append(new)
204+
if additional != []:
205+
json_record["additional_descriptions"] = additional
198206

199207
# dates
200208
if "dates" in json_record:

0 commit comments

Comments
 (0)