Last active
April 18, 2024 19:14
-
-
Save bsesic/7b3bff70c6f8deaf71e2f0e9484c9952 to your computer and use it in GitHub Desktop.
Get GND 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
import requests | |
def get_gnd_id(name: str, type: str) -> str: | |
"""Get the GND ID for a given name and type. | |
Args: | |
name (str): Name of the entity. | |
type (str): Type of the entity. | |
Returns: | |
str: GND ID of the entity. | |
""" | |
try: | |
request = requests.get( | |
"https://lobid.org/gnd/search?q=" + name + "&filter=type:" + type + "&format=json" | |
) | |
request_json = request.json() | |
#print(json.dumps(request_json, indent=4)) | |
gnd_id = request_json["member"][0]["gndIdentifier"] | |
return gnd_id | |
except: | |
print("No GND ID found for " + name + " of type " + type + ".") | |
return None | |
# test it | |
print(get_gnd_id("Bach, Johann Sebastian", "Person")) | |
print(get_gnd_id("Löb, Aach", "Person")) | |
print(get_gnd_id("Aachen", "PlaceOrGeographicName")) | |
print(get_gnd_id("Komponist", "professionOrOccupation")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function fetches the GND Id for a person or a place with a given type.