Created
December 1, 2023 10:35
-
-
Save bsesic/6aceb5c8fcf9a3db3e2eb8339d0e479f to your computer and use it in GitHub Desktop.
Get VIAF ID
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def get_viaf_id(gnd_id: str) -> str: | |
""" | |
Get the VIAF ID for a given GND ID. | |
Args: gnd_id (str): GND ID of the entity. | |
Returns: str: VIAF ID of the entity. | |
""" | |
try: | |
request = requests.get( | |
"https://lobid.org/gnd/" + gnd_id + ".json" | |
) | |
request_json = request.json() | |
#print(json.dumps(request_json, indent=4)) | |
for sameAs in request_json["sameAs"]: | |
if sameAs["collection"]["abbr"] == "VIAF": | |
print("VIAF ID found for " + gnd_id + ".") | |
viaf_id = sameAs["id"] | |
return viaf_id | |
print("No VIAF ID found for " + gnd_id + ".") | |
return None | |
except: | |
print("No VIAF ID found for " + gnd_id + ".") | |
return None | |
# test it | |
print(get_viaf_id("11850553X")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function gets the VIAF ID from a GND ID of an entity.