Skip to content

Instantly share code, notes, and snippets.

@bsesic
Created December 1, 2023 10:35
Show Gist options
  • Save bsesic/6aceb5c8fcf9a3db3e2eb8339d0e479f to your computer and use it in GitHub Desktop.
Save bsesic/6aceb5c8fcf9a3db3e2eb8339d0e479f to your computer and use it in GitHub Desktop.
Get VIAF ID
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"))
@bsesic
Copy link
Author

bsesic commented Apr 18, 2024

This function gets the VIAF ID from a GND ID of an entity.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment