From 28b56ea4418d88dfbe473abf8f035506069e121a Mon Sep 17 00:00:00 2001 From: jules Date: Thu, 19 Nov 2020 01:02:12 +0100 Subject: [PATCH] more work on artwork page --- daapinterface.py | 197 +++++++++++++++++++++++++-------------- templates/artwork.html | 203 +++++++++++++++++++++++++++++++++++------ 2 files changed, 303 insertions(+), 97 deletions(-) diff --git a/daapinterface.py b/daapinterface.py index 7043c53..ba5d4e8 100644 --- a/daapinterface.py +++ b/daapinterface.py @@ -252,7 +252,68 @@ def artwork(): sparql.setReturnFormat(JSON) artworkimages = sparql.query().convert() - print(artworkimages) + # print(artworkimages) + +# Links and downloads + sparql.setQuery(''' + SELECT ?DownloadDigitalFacsimile ?DigitalFacsimileExternalLink ?DigitalFacsimileExternalLink2 + WHERE + { + VALUES ?work {wd:'''+artwork_id+'''} + OPTIONAL {?work wdt:P32 ?DownloadDigitalFacsimile.} + OPTIONAL {?work wdt:P34 ?DigitalFacsimileExternalLink.} + OPTIONAL {?work wdt:P33 ?DigitalFacsimileExternalLink2.} + SERVICE wikibase:label { bd:serviceParam wikibase:language "en".} + }''') + sparql.setReturnFormat(JSON) + artworklinksanddownloads = sparql.query().convert() + print(artworklinksanddownloads) + +# Other digital artefacts + sparql.setQuery(''' + SELECT ?ImageFile ?AudioFile ?VideoFile + WHERE + { + { + SELECT ?ImageFile WHERE { + VALUES ?work {wd:Q57} + OPTIONAL {?work p:P35 ?statement. + ?statement ps:P35 ?ImageFile; + pq:P16 wd:Q85.} + }} + { + SELECT ?AudioFile WHERE { + OPTIONAL {?work p:P35 ?statement. + ?statement ps:P35 ?AudioFile; + pq:P16 wd:Q28.} + }} + { + SELECT ?VideoFile WHERE { + OPTIONAL {?work p:P35 ?statement. + ?statement ps:P35 ?VideoFile; + pq:P16 wd:Q27.} + }} + SERVICE wikibase:label { bd:serviceParam wikibase:language "en".} + } + ''') + sparql.setReturnFormat(JSON) + artworkartefacts = sparql.query().convert() + # print(artworkartefacts) + + +# Distributor Links + sparql.setQuery(''' + SELECT ?distributorLinks + WHERE + { + VALUES ?work {wd:'''+artwork_id+'''} + OPTIONAL {?work wdt:P37 ?distributorLinks.} + SERVICE wikibase:label { bd:serviceParam wikibase:language "en".} + } + ''') + sparql.setReturnFormat(JSON) + artworkdistributorlinks = sparql.query().convert() + ######### Right top # contributors @@ -332,21 +393,15 @@ def artwork(): ''') sparql.setReturnFormat(JSON) artworkdescriptiondata = sparql.query().convert() - # print("hello") - # print(artwork_id) - # print(artworkdescriptiondata) - # print("bye") - dictionary = artworkdescriptiondata - # print(type(dictionary)) # get the description text or say there isn't any - artworkdescriptiontext = None + # artworkdescriptiontext = [] - for x in dictionary['results']['bindings']: + for x in artworkdescriptiondata['results']['bindings']: if "accessURLdescriptionPage" in x: - print("url for description present") - print(x["accessURLdescriptionPage"]["value"]) + # print("url for description present") + # print(x["accessURLdescriptionPage"]["value"]) accessURLdescriptionUrl = x["accessURLdescriptionPage"]["value"] desc_url = re.search(r':Q(.*)', accessURLdescriptionUrl, re.DOTALL) # print(desc_url.group(1)) @@ -360,56 +415,60 @@ def artwork(): # # print(soup.prettify()) # print the parsed data of html text=soup.find("div" , {"class" : "mw-parser-output"}) # text=soup.find_all("p") - artworkdescriptiontext=Markup(text) + # text=Markup(text) + # artworkdescriptiontext.append(text) + x["text"] = text else: - print("url for description absent") + # print("url for description absent") text="

Information not available

" - artworkdescriptiontext=Markup(text) - - #description Q427 for testing purposes - # artworkdescriptioncontenturl = "https://daap.bannerrepeater.org/w/index.php?title=Description:Q427&action=render" - # Make a GET request to fetch the raw HTML content - # html_content = requests.get(artworkdescriptioncontenturl).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") - # artworkdescriptiontext=Markup(text) + x["text"] = text - # print(artworkdescriptiontext) - -############ right bottom LATER # exhibitions + id to be changed sparql.setQuery(''' - SELECT ?accessURLexhibitionHisPage ?authorexhibitionHisPageLabel ?dateexhibitionHisPage ?sourceexhibitionHisPage + SELECT ?accessURLexhibitionHisPage ?authorexhibitionHisPageLabel ?dateexhibitionHisPage ?sourceexhibitionHisPage WHERE { - VALUES ?work {wd:Q57} + VALUES ?work {wd:'''+artwork_id+'''} ?work wdt:P66 ?exhibitionHisPage. OPTIONAL { ?exhibitionHisPage wdt:P4 ?accessURLexhibitionHisPage. } OPTIONAL { ?exhibitionHisPage wdt:P9 ?authorexhibitionHisPage. } OPTIONAL { ?exhibitionHisPage wdt:P13 ?dateexhibitionHisPage. } - OPTIONAL { ?exhibitionHisPage wdt:P50 ?sourceexhibitionHisPage. } + OPTIONAL { ?exhibitionHisPage wdt:P50 ?sourceexhibitionHisPage. } SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ''') sparql.setReturnFormat(JSON) artworkexhibitiondata = sparql.query().convert() - # description content from wiki - artworkexhibitioncontenturl = "https://daap.bannerrepeater.org/w/index.php?title=History:"+artwork_id+"&action=render" - # Make a GET request to fetch the raw HTML content - html_content = requests.get(artworkexhibitioncontenturl).text - # Parse the html content - soup = BeautifulSoup(html_content, "lxml") - # print(soup.prettify()) # print the parsed data of html + # get the text from the url + for x in artworkexhibitiondata['results']['bindings']: + if "accessURLexhibitionHisPage" in x: + # print("url for description present") + # print(x["accessURLexhibitionHisPage"]["value"]) + accessURLexhibitionHisPage = x["accessURLexhibitionHisPage"]["value"] + desc_url = re.search(r':Q(.*)', accessURLexhibitionHisPage, re.DOTALL) + # print(desc_url.group(1)) + desc_id=desc_url.group(1) + # # get the description content from wiki + artworkexhibitioncontenturl = "https://daap.bannerrepeater.org/w/index.php?title=History:Q"+desc_id+"&action=render" + # # Make a GET request to fetch the raw HTML content + html_content = requests.get(artworkexhibitioncontenturl).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") + # artworkexhibitiontext=Markup(text) + x['text']=text + else: + # print("url for description absent") + text="

Information not available

" + # artworkexhibitiontext=Markup(text) + x['text']=text + + # print(artworkexhibitiondata) - text=soup.find("div" , {"class" : "mw-parser-output"}) - # text=soup.find_all("p") - artworkexhibitiontext=Markup(text) - # print(artworkexhibitiontext) ############## bottom # copies in collection @@ -425,7 +484,6 @@ def artwork(): } ''') sparql.setReturnFormat(JSON) copiesincollection = sparql.query().convert() - # print(copiesincollection) # related works sparql.setQuery(''' @@ -446,12 +504,29 @@ def artwork(): } ''') sparql.setReturnFormat(JSON) relatedworks = sparql.query().convert() - # print(relatedworks) + +# lists + sparql.setQuery(''' + SELECT ?list ?listLabel ?image ?date + WHERE + { + VALUES ?work {wd:'''+artwork_id+'''} + ?work wdt:P45 ?list. + OPTIONAL {?list wdt:P13 ?date.} + OPTIONAL {?list wdt:P30 ?image.} + SERVICE wikibase:label { bd:serviceParam wikibase:language "en".} + } + ''') + sparql.setReturnFormat(JSON) + artworklists = sparql.query().convert() + # print(artworklists) + + 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) - return render_template('artwork.html', artwork_id=artwork_id, artworkintro=artworkintro, artworkimages=artworkimages, artworkcontributors=artworkcontributors, artworkdate=artworkdate, artworkpublisher=artworkpublisher, artworkdescriptiondata=artworkdescriptiondata, artworkdescriptiontext=artworkdescriptiontext, copiesincollection=copiesincollection, relatedworks=relatedworks) +######################### ORGANISATION @@ -462,13 +537,11 @@ def artwork(): def person(): person_id = request.args.get('id') sparql.setQuery(''' - SELECT ?item ?itemLabel ?itemDescription ?propLabel ?b ?bLabel WHERE { VALUES ?item {wd:'''+person_id+'''} ?item ?a ?b. - SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } ?prop wikibase:directClaim ?a . } @@ -478,7 +551,7 @@ def person(): print(person_details) - sparql2.setQuery(''' + sparql.setQuery(''' SELECT ?work ?workLabel ?image ?date WHERE { SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } @@ -490,10 +563,10 @@ def person(): } ORDER BY (?workLabel) ''') - sparql2.setReturnFormat(JSON) - person_creatorof = sparql2.query().convert() + sparql.setReturnFormat(JSON) + person_creatorof = sparql.query().convert() - sparql3.setQuery(''' + sparql.setQuery(''' SELECT ?work ?workLabel ?image ?date WHERE { SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } @@ -505,8 +578,8 @@ def person(): } ORDER BY (?workLabel) ''') - sparql3.setReturnFormat(JSON) - person_publisherof = sparql2.query().convert() + sparql.setReturnFormat(JSON) + person_publisherof = sparql.query().convert() person_url = "" person_name = "the name" @@ -541,12 +614,11 @@ def about(): # print(soup.prettify()) # print the parsed data of html text=soup.find("html") - # adapt the path to img with regex + # A problem with image src obtention was solved by using absolute paths rather than traditional wiki syntax # replaceString = "wiki/Special:Redirect/file/" # cleanSoup = BeautifulSoup(str(text).replace("wiki/File:", replaceString)) - # for a in soup.find_all('a', href=True): # if a.text: # print(a['href']) @@ -626,21 +698,6 @@ def codeofconduct(): ######################### LOGIN #Goes to wikibase page -# ################### -# TEST - -response = requests.get( - 'https://daap.bannerrepeater.org/w/api.php', - params={ - 'action': 'parse', - 'page': 'Test', - 'format': 'json', - }).json() -raw_html = response['parse']['text']['*'] -document = html.document_fromstring(raw_html) -first_p = document.xpath('//p')[0] -intro_text = first_p.text_content() -# print(intro_text) # ALL NAME diff --git a/templates/artwork.html b/templates/artwork.html index 4ed08ce..ebeb48c 100644 --- a/templates/artwork.html +++ b/templates/artwork.html @@ -1,9 +1,10 @@ {% extends "layout.html" %} {% block content %} +
- +
@@ -27,37 +28,102 @@
ABOUT THIS WORK
-
RELATIONSHIPS
-
LISTS
+ +
- - +
- +
- +
{% if artworkimages['results']['bindings']==[] %} {% else %} - {% for x in artworkimages["results"]["bindings"] %} - + {% for x in artworkimages['results']['bindings'] %} + {% if loop.index <= 1 %} + {% if "image" in x %} + + {% endif %} + {% endif %} {% endfor %} {% endif %}
-
+ + +
+ {% if artworklinksanddownloads['results']['bindings']==[] %} + {% else %} + {% for x in artworklinksanddownloads['results']['bindings'] %} +

DOWNLOADS AND LINKS

+ + {% if 'DownloadDigitalFacsimile' in x %} +
+ + Download digital facsimile +
+ {% endif %} + + {% if 'DigitalFacsimileExternalLink' in x %} +
+ + External digital facsimile linl +
+ {% endif %} + + {% if 'DigitalFacsimileExternalLink2' in x %} +
+ + External digital facsimile link 2 +
+ {% endif %} + + + {% endfor %} + {% endif %} +
+ + +
+ {% if artworkartefacts['results']['bindings']==[] %} +

OTHER DIGTAL ARTEFACTS

+ + {% for x in artworkartefacts['results']['bindings'] %} + {{ x }} + {% endfor %} + {% endif %} +
+ + +
+ {% if artworkdistributorlinks['results']['bindings']==[] %} + {% else %} +

DISTRIBUTOR LINKS

+ {% for x in artworkdistributorlinks['results']['bindings'] %} + {% if 'distributorLinks' in x %} + + {% endif %} + {% endfor %} +

+ + {% endif %} +
+
+
- - - + +
+

CONTRIBUTORS

@@ -111,31 +177,88 @@
+ +
-
- DESCRIPTION + {% if artworkdescriptiondata['results']['bindings']==[] %} + {% else %} + + {% for x in artworkdescriptiondata['results']['bindings'] %} +
+

DESCRIPTION

- {{ artworkdescriptiontext }} +
+ {{ x["text"] | safe }} +
- - +
+ {% if "authordescriptionPageLabel" in x %} +

AUTHOR

+

{{ x['authordescriptionPageLabel']['value'] }}

+ {% endif %} - + + {% if "sourcedescriptionPage" in x %} +

SOURCE

+

{{ x["sourcedescriptionPage"]["value"]}}

- + {% endif %} + + + {% if "datedescriptionPage" in x %} +

DATE

+

{{ x["datedescriptionPage"]["value"] | replace("T00:00:00Z", "") }}

+ {% endif %} - +
+
+ {% endfor %} + {% endif %} -
+ + {% if artworkexhibitiondata['results']['bindings']==[] %} + {% else %} + + {% for x in artworkexhibitiondata['results']['bindings'] %} +
+

EXHIBITION AND DISTRIBUTION HISTORY

+ +
+ {{ artworkexhibitiontext | safe }} +
+ +
+

AUTHOR

+ + {% if "authorexhibitionHisPageLabel" in x %} +

{{ x["authorexhibitionHisPageLabel"]["value"]}}

+ {% endif %} + +

SOURCE

+ + {% if "sourceexhibitionHisPage" in x%} +

{{ x["sourceexhibitionHisPage"]["value"]}}

+ {% endif %} + +

DATE

+ + {% if "dateexhibitionHisPage" in x%} +

{{ x["dateexhibitionHisPage"]["value"] | replace("T00:00:00Z", "") }}

+ {% endif %} +
+ +
+ {% endfor %} + {% endif %} @@ -143,10 +266,36 @@
- -
- -
+ +
LISTS
+
+ {% if artworklists['results']['bindings']==[] %} +

The artwork isn't featured in any lists yet

+ {% else %} +

This artwork is featured in the following lists:

+ {% for x in artworklists['results']['bindings'] %} +
+
+ {% if "image" in x %} + + {% else %} + + {% endif %} +
+
+ {% if "listLabel" in x %} + {{ x['listLabel']['value'] }} + {% endif %} +
+
+ placeholder for number of artworks in list +
+ +
+ {% endfor %} + {% endif %} +
+