Last active
April 18, 2024 19:45
-
-
Save bsesic/7e32bd323ae912acd79a993f07a7e6d4 to your computer and use it in GitHub Desktop.
check profession
This file contains 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 | |
# 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")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This function takes a given occupation and check if it exists in the GND categories. If it exists true is returned.