Skip to content

Commit

Permalink
Merge pull request #106 from arthur-schnitzler/main
Browse files Browse the repository at this point in the history
code updates
  • Loading branch information
csae8092 authored Nov 9, 2024
2 parents 3b76fdc + ce1ad06 commit 5aed720
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 26 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ jobs:
options: --health-cmd pg_isready --health-interval 10s --health-timeout 5s --health-retries 5
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
- name: Set up Python 3.12
uses: actions/setup-python@v5
with:
python-version: "3.11"
python-version: "3.12"
- uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
Expand Down
40 changes: 18 additions & 22 deletions apis_core/apis_metainfo/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,30 +16,26 @@
from .models import Uri

PROJECT_NAME = settings.PROJECT_NAME
BEACON_NAME = f"#FORMAT: BEACON\n#NAME: {PROJECT_NAME}\n"


def beacon(request):
domain = request.build_absolute_uri("/")
result = f"#FORMAT: BEACON\n#NAME: {PROJECT_NAME}\n"
uris = [
(x.uri, x.entity.name, x.entity.id)
for x in Uri.objects.filter(uri__icontains="d-nb.info/gnd")
]
for x in uris:
result = result + f"{x[0]}|" f"{x[1]}|" f"{domain}entity/{x[2]}/\n"
return HttpResponse(result, content_type="text/plain")


def wikidata_beacon(request):
domain = request.build_absolute_uri("/")
result = f"#FORMAT: BEACON\n#NAME: {PROJECT_NAME}\n"
uris = [
(x.uri, x.entity.name, x.entity.id)
for x in Uri.objects.filter(uri__icontains="wikidata.org/entity/")
]
for x in uris:
result = result + f"{x[0]}|" f"{x[1]}|" f"{domain}entity/{x[2]}/\n"
return HttpResponse(result, content_type="text/plain")
def beacon(request, domain="d-nb.info/gnd"):
result = BEACON_NAME
df = pd.DataFrame(
list(
Uri.objects.filter(uri__icontains=domain).values(
"uri",
"entity__name",
"entity_id",
)
)
)
df["entity_id"] = df.apply(
lambda row: f'https://pmb.acdh.oeaw.ac.at/entity/{row["entity_id"]}/', axis=1
)
beacon_lines = df[['uri', 'entity__name', 'entity_id']].agg('|'.join, axis=1)
beacon_str = result + "\n".join(beacon_lines)
return HttpResponse(beacon_str, content_type="text/plain; charset=utf-8")


def domain_uris(request, domain):
Expand Down
9 changes: 7 additions & 2 deletions apis_core/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from rest_framework import routers

from apis_core.api_routers import views
from apis_core.apis_metainfo.views import beacon, wikidata_beacon, domain_uris
from apis_core.apis_metainfo.views import beacon, domain_uris
from apis_core.apis_vocabularies.api_views import UserViewSet
from apis_core.helper_functions.ContentType import GetContentTypes
from apis_core.apis_entities.autocomplete3 import GenericEntitiesAutocomplete
Expand Down Expand Up @@ -44,7 +44,12 @@
name="network-ac",
),
path("gnd-beacon/", beacon, name="beacon"),
path("wikidata-beacon/", wikidata_beacon, name="wikidata_beacon"),
path(
"wikidata-beacon/",
beacon,
{"domain": "wikidata.org/entity/"},
name="wikidata_beacon",
),
path("domain-uris/<str:domain>", domain_uris, name="domain_uris"),
path("labels/", include("apis_core.apis_labels.urls", namespace="apis_labels")),
path("tei/", include("apis_core.apis_tei.tei_urls", namespace="apis_tei")),
Expand Down

0 comments on commit 5aed720

Please sign in to comment.