Skip to content

Commit

Permalink
Merge pull request #51 from arthur-schnitzler/main
Browse files Browse the repository at this point in the history
updates
  • Loading branch information
csae8092 authored Jan 23, 2024
2 parents 30064d8 + c4814ca commit 7393153
Show file tree
Hide file tree
Showing 9 changed files with 107 additions and 7 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,10 @@ jobs:
steps:
- uses: actions/checkout@v4
- name: Set up Python 3.11
uses: actions/setup-python@v4
uses: actions/setup-python@v5
with:
python-version: "3.11"
- uses: actions/cache@v3
- uses: actions/cache@v4
with:
path: ${{ env.pythonLocation }}
key: ${{ env.pythonLocation }}-${{ hashFiles('requirements.txt') }}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
from apis_core.apis_entities.models import Person
from dumper.utils import write_report

warnings.filterwarnings('ignore')
warnings.filterwarnings("ignore")


class Command(BaseCommand):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,12 @@ <h3 class="text-center">
{% if object.img_url %}
<div class="text-center p-3">
<img src="{{ object.img_url }}" class="rounded" alt="Bild von {{ object }}" style="height: 200px">
{% if object.img_credit %}
<figcaption class="figure-caption"><a href="{{ object.img_url }}">{{ object.img_credit }}</a></figcaption>
{% endif %}
</div>


{% endif %}
{% block info-table %}
<table class="table">
Expand Down
5 changes: 5 additions & 0 deletions apis_core/apis_entities/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,3 +370,8 @@ def test_026_fetch_image(self):
entity = import_from_normdata(grillparzer, "person")
entity.fetch_image()
self.assertTrue(entity.img_url)
self.assertTrue("Wikimedia Commons" in entity.img_credit())

def test_027_img_credit(self):
entity = import_from_normdata("https://www.wikidata.org/wiki/Q76483", "person")
self.assertIsNone(entity.img_credit())
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ class Migration(migrations.Migration):
model_name="tempentityclass",
name="img_last_checked",
field=models.DateTimeField(
blank=True, null=True, verbose_name="geprüft am",
help_text="Datum an dem die Bild-URL eingetragen wurde."
blank=True,
null=True,
verbose_name="geprüft am",
help_text="Datum an dem die Bild-URL eingetragen wurde.",
),
),
migrations.AddField(
Expand Down
7 changes: 7 additions & 0 deletions apis_core/apis_metainfo/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,13 @@ def fetch_image(self):
self.save()
return self

def img_credit(self):
credit = None
if self.img_url is not None:
if "commons.wikimedia.org/w/index" in self.img_url:
credit = "Wikimedia Commons"
return credit

@classmethod
def get_listview_url(self):
entity = self.__name__.lower()
Expand Down
81 changes: 81 additions & 0 deletions issue__112_fix_image_urls.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
{
"cells": [
{
"cell_type": "code",
"execution_count": null,
"id": "eda7419e",
"metadata": {},
"outputs": [],
"source": [
"from urllib.parse import quote\n",
"from acdh_wikidata_pyutils import URL_STUB\n",
"from tqdm.notebook import tqdm"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "f03b29bb",
"metadata": {},
"outputs": [],
"source": [
"items = TempEntityClass.objects.filter(img_url__icontains=\"width\").filter(img_url__icontains=\"commons.wikimedia.org/w/index\")"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "e8e31fb5",
"metadata": {},
"outputs": [],
"source": [
"items.count()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "8ec94f95",
"metadata": {},
"outputs": [],
"source": [
"for x in tqdm(items, total=len(items)):\n",
" img_name = x.img_url.split('/')[-1].split('&')[0]\n",
" new_url = URL_STUB.format(quote(img_name))\n",
" if len(new_url) > 300:\n",
" new_url = None\n",
" x.img_url = new_url\n",
" x.save()"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "454dd98d",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Django Shell-Plus",
"language": "python",
"name": "django_extensions"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.10.12"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ acdh-django-browsing
acdh_geonames_utils
acdh-id-reconciler>=0.2,<1
acdh-tei-pyutils>=0.34,<1
acdh-wikidata-pyutils>=0.5,<1
acdh-wikidata-pyutils==1.0
apis-override-select2js==0.1
Django>4.1,<6
django-admin-csvexport
Expand Down
2 changes: 1 addition & 1 deletion set_env_variables.sh
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export $(grep -v '^#' .env | xargs)
export $(grep -v '^#' .secret | xargs)

0 comments on commit 7393153

Please sign in to comment.