diff --git a/daapinterface.py b/daapinterface.py index 5323f5c..d4d408e 100644 --- a/daapinterface.py +++ b/daapinterface.py @@ -536,6 +536,121 @@ def artwork(): return render_template('artwork.html', artwork_id=artwork_id, artworkintro=artworkintro, artworkimages=artworkimages, artworklinksanddownloads=artworklinksanddownloads, artworkartefacts=artworkartefacts, artworkdistributorlinks=artworkdistributorlinks, artworkcontributors=artworkcontributors, artworkdate=artworkdate, artworkpublisher=artworkpublisher, artworkdescriptiondata=artworkdescriptiondata, artworkexhibitiondata=artworkexhibitiondata, artworklists=artworklists, copiesincollection=copiesincollection, relatedworks=relatedworks) +######################### COPY ITEM +@app.route("/copy", methods=['GET']) +def copy(): + copy_id = request.args.get('id') + + # Intro + sparql.setQuery(''' + SELECT ?item ?itemLabel ?itemDescription ?itemtypeLabel + { + VALUES ?item {wd:'''+copy_id+'''} + ?item wdt:P1 ?itemtype. + SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } + } + ''') + sparql.setReturnFormat(JSON) + copyintro = sparql.query().convert() + +# image + sparql.setQuery(''' + SELECT ?image ?depictsLabel ?licenseLabel + WHERE + { + VALUES ?item {wd:'''+copy_id+'''} + ?item wdt:P90 ?image. + OPTIONAL { ?work p:P90 ?statement2. + ?statement2 ps:P90 ?image; + pq:P54 ?depicts; + pq:P56 ?license.} + SERVICE wikibase:label { bd:serviceParam wikibase:language "en".} + } + ''') + sparql.setReturnFormat(JSON) + copyimage = sparql.query().convert() + +# copy of + sparql.setQuery(''' + SELECT ?work ?workLabel + WHERE + { + VALUES ?item {wd:'''+copy_id+'''} + ?item wdt:P46 ?work. + SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } + } + ''') + sparql.setReturnFormat(JSON) + copyof = sparql.query().convert() + +# collection + sparql.setQuery(''' + SELECT ?collection ?collectionLabel + WHERE + { + VALUES ?item {wd:'''+copy_id+'''} + ?item wdt:P47 ?collection. + SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } + } + ''') + sparql.setReturnFormat(JSON) + copycollection = sparql.query().convert() + +# inventory number + sparql.setQuery(''' + SELECT ?inventoryNumber + WHERE + { + VALUES ?item {wd:'''+copy_id+'''} + ?item wdt:P48 ?inventoryNumber. + SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } + } + ''') + sparql.setReturnFormat(JSON) + copyinventorynumber = sparql.query().convert() + + +# copy description + sparql.setQuery(''' + SELECT ?accessURLdescriptionPage ?authordescriptionPageLabel ?datedescriptionPage ?sourcedescriptionPageLabel + WHERE + { + VALUES ?item {wd:'''+copy_id+'''} + ?item wdt:P65 ?descriptionPage. + OPTIONAL { ?descriptionPage wdt:P4 ?accessURLdescriptionPage. } + OPTIONAL { ?descriptionPage wdt:P9 ?authordescriptionPage. } + OPTIONAL { ?descriptionPage wdt:P13 ?datedescriptionPage. } + OPTIONAL { ?descriptionPage wdt:P50 ?sourcedescriptionPage. } + SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } + } + ''') + sparql.setReturnFormat(JSON) + copydescription = sparql.query().convert() + + for x in copydescription['results']['bindings']: + if "accessURLdescriptionPage" in x: + accessURLdescURL = x["accessURLdescriptionPage"]["value"] + desc_url = re.search(r':Q(.*)', accessURLdescURL, re.DOTALL) + desc_id=desc_url.group(1) + # # get the description content from wiki + copydesccontenturl = "https://daap.bannerrepeater.org/w/index.php?title=Description:Q"+desc_id+"&action=render" + # # Make a GET request to fetch the raw HTML content + html_content = requests.get(copydesccontenturl).text + # # Parse the html content + soup = BeautifulSoup(html_content, "lxml") + # # print(soup.prettify()) # print the parsed data of html + text=soup.find("div" , {"class" : "mw-parser-output"}) + # text=soup.find_all("p") + # text=Markup(text) + # artworkdescriptiontext.append(text) + x["text"] = text + else: + # print("url for description absent") + text="

Information not available

" + x["text"] = text + + + return render_template('copy.html', copy_id=copy_id, copyintro=copyintro, copyimage=copyimage, copyof=copyof, copycollection=copycollection, copyinventorynumber=copyinventorynumber, copydescription=copydescription) ######################### ITEM : COLLECTIVE - PERSON - ORGANISATION diff --git a/templates/copy.html b/templates/copy.html new file mode 100644 index 0000000..d3be2f2 --- /dev/null +++ b/templates/copy.html @@ -0,0 +1,227 @@ +{% extends "layout.html" %} +{% block content %} + + +
+ + +
+ +
+ COPY ITEM +
+ +
+ {% for x in copyintro['results']['bindings'] %} + {{ x['itemLabel']['value'] }} + {% endfor %} +
+ +
+ {% for x in copyintro['results']['bindings'] %} + {% if 'itemDescription' in x %} + {{ x['itemDescription']['value'] }} + {% endif %} + {% endfor %} +
+ + +
+
ABOUT
+ + + +
+
+ + + + + + + + +
+ + + +
+ + +
+ {% if copyimage['results']['bindings']==[] %} + + {% else %} + + {% for x in copyimage['results']['bindings'] %} +
+ + {% if "image" in x %} + + + {% endif %} + + {% if "depictsLabel" in x %} +

{{ x['depictsLabel']['value'] }}

+ {% endif %} + + {% if "licenseLabel" in x %} +

License: {{ x['licenseLabel']['value'] }}

+ {% endif %} + +
+ {% endfor %} + + {% endif %} +
+ +
+ + + + + + + + +
+ + + + +
+ + +
+ + +

COPY OF

+{% if copyof['results']['bindings']==[] %} +
information not available
+ {% else %} + {% for x in copyof['results']['bindings'] %} + + {% endfor %} + {% endif %} + + + +

COLLECTION

+{% if copycollection['results']['bindings']==[] %} +
information not available
+ {% else %} + {% for x in copycollection['results']['bindings'] %} + + {% endfor %} + {% endif %} + + + + + + +

INVENTORY NUMBER

+{% if copyinventorynumber['results']['bindings']==[] %} +
information not available
+ {% else %} + + {% for x in copyinventorynumber['results']['bindings'] %} + #{{ x['inventoryNumber']['value'] }} + {% endfor %} + {% endif %} + + +
+ + + + +
+ + + + + + + + + + + +
+

DESCRIPTION

+ {% if copydescription['results']['bindings']==[] %} +

information not available

+ {% else %} + + + {% for x in copydescription['results']['bindings'] %} +
+ +
+ {{ x["text"] | safe }} +
+
+ {% endfor %} + {% endif %} + +
+ + + + + + + + + + +
+ + + +
+ + + + + + + +
+ + + + + + +{% endblock content %} \ No newline at end of file