Skip to content

Commit

Permalink
Fetching additional information from GND
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexanderWatzinger committed Aug 7, 2024
1 parent 0381a24 commit 5038a05
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions openatlas/api/external/gnd.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
import requests
from flask import g

from openatlas.display.util import link


def print_values(values: dict[str: str]) -> str:
items = []
for item in values:
items.append(link(item["label"], item["id"], external=True))
return '<br>'.join(items)


def fetch_gnd(id_: str) -> dict[str, Any]:
url = f'{g.gnd.resolver_url}{id_}.json'
Expand All @@ -13,4 +22,17 @@ def fetch_gnd(id_: str) -> dict[str, Any]:
return {}
if 'preferredName' in data:
info['preferred name'] = data['preferredName']
if 'gender' in data:
info['gender'] = print_values(data['gender'])
if 'dateOfBirth' in data:
info['date of birth'] = data['dateOfBirth']
if 'placeOfBirth' in data:
info['place of birth'] = print_values(data['placeOfBirth'])
if 'dateOfDeath' in data:
info['date of death'] = data['dateOfDeath']
if 'placeOfDeath' in data:
info['place of death'] = print_values(data['placeOfDeath'])
if 'type' in data:
info['type'] = '<br>'.join(data['type'])

return info

0 comments on commit 5038a05

Please sign in to comment.