Skip to content

Commit

Permalink
fix: replace profession with new type and add debug msgs
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Sep 27, 2023
1 parent 97264ef commit 0f3713e
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions apis_ontology/management/commands/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

from django.contrib.contenttypes.models import ContentType

from apis_ontology.models import Event, Institution, Person, Place, Work, Title
from apis_ontology.models import Event, Institution, Person, Place, Work, Title, Profession
from apis_core.apis_metainfo.models import Uri, RootObject

SRC="https://apis.acdh.oeaw.ac.at/apis/api"
Expand Down Expand Up @@ -40,11 +40,16 @@ def handle(self, *args, **options):
data = page.json()
nextpage = data['next']
for result in data["results"]:
print(result["url"])
result_id = result["id"]
if "kind" in result and result["kind"] is not None:
result["kind"] = result["kind"]["label"]
if "profession" in result and result["profession"] is not None:
result["profession"] = ",".join([x["label"] for x in result["profession"]])
professionlist = []
if "profession" in result:
for profession in result["profession"]:
newprofession, created = Profession.objects.get_or_create(name=profession["label"])
professionlist.append(newprofession)
del result["profession"]
titlelist = []
if "title" in result:
for title in result["title"]:
Expand All @@ -57,6 +62,8 @@ def handle(self, *args, **options):
setattr(newentity, attribute, result[attribute])
for title in titlelist:
newentity.title.add(title)
for profession in professionlist:
newentity.profession.add(profession)
newentity.save()

# Migrate URIs
Expand Down

0 comments on commit 0f3713e

Please sign in to comment.