Skip to content

Commit

Permalink
Merge pull request #131 from acdh-oeaw/report-in-md
Browse files Browse the repository at this point in the history
Print report in markdown
  • Loading branch information
gythaogg authored Sep 23, 2024
2 parents 53ab30c + 86a3bf2 commit 4a9823c
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 deletions apis_ontology/management/commands/get_tei_refs.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,22 +29,29 @@ def get_all_tei_ids(value):
models = TibScholRelationMixin.__subclasses__()
unique_refs = defaultdict(list)
for m in tqdm(models):
model_name = str(m).split("'")[1].split(".")[-1]
if not hasattr(m, "tei_refs"):
break
for rel in m.objects.all():
if rel.tei_refs:
all_tei_refs = get_all_tei_ids(rel.tei_refs)
for ref in all_tei_refs:
unique_refs[ref].append(f"{rel.pk},{m},{rel.subj},{rel.obj}")
unique_refs[ref].append(
f"{rel.pk}|{model_name}|{rel.subj.pk}|{rel.obj.pk}"
)

missing_refs = []
for ref in unique_refs.keys():
try:
Excerpts.objects.get(xml_id=ref)
except Excerpts.DoesNotExist as e:
missing_refs.append(f"{ref},{unique_refs[ref]}")
for support in unique_refs[ref]:
missing_refs.append(f"|{ref}|{support}|")

with open(f"missing_refs_{datetime.now():%Y%M%d_%H%m%S}.csv", "w") as f:
with open(f"missing_refs_{datetime.now():%Y%m%d_%H%M%S}.md", "w") as f:
f.writelines(
"|TEI ID|RELATION PK|Relation|Subject PK|Object PK|\n|--|--|--|--|--|\n"
)
f.writelines("\n".join(missing_refs))

self.stdout.write(self.style.SUCCESS("Done."))

0 comments on commit 4a9823c

Please sign in to comment.