Skip to content

Instantly share code, notes, and snippets.

@bsesic
Last active April 18, 2024 19:45
Show Gist options
  • Save bsesic/7e32bd323ae912acd79a993f07a7e6d4 to your computer and use it in GitHub Desktop.
Save bsesic/7e32bd323ae912acd79a993f07a7e6d4 to your computer and use it in GitHub Desktop.
check profession
import requests
# Check if a profession is in the GND
def check_profession(profession: str) -> bool:
"""Check if a profession is in the GND.
Args:
profession (str): Profession to check.
Returns:
bool: True if the profession is in the GND, False otherwise.
"""
try:
request = requests.get(
"https://lobid.org/gnd/search?q=" + profession + "&format=json:professionOrOccupation"
)
request_json = request.json()
#print(json.dumps(request_json, indent=4))
# return true if category matches with Schlagwort
for item in request_json:
#print(item["category"])
#print(item["label"])
#print(item["id"])
# check if category begins with Schlagwort
if item["category"].startswith("Schlagwort"):
return True
return False
except KeyError:
print(profession + " not found.")
return False
# test it
print(check_profession("Rabbiner"))
@bsesic
Copy link
Author

bsesic commented Apr 18, 2024

This function takes a given occupation and check if it exists in the GND categories. If it exists true is returned.

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