Browse Source

more work on artwork page

master
jules 4 years ago
parent
commit
28b56ea441
  1. 193
      daapinterface.py
  2. 203
      templates/artwork.html

193
daapinterface.py

@ -252,7 +252,68 @@ def artwork():
sparql.setReturnFormat(JSON) sparql.setReturnFormat(JSON)
artworkimages = sparql.query().convert() 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 ######### Right top
# contributors # contributors
@ -332,21 +393,15 @@ def artwork():
''') ''')
sparql.setReturnFormat(JSON) sparql.setReturnFormat(JSON)
artworkdescriptiondata = sparql.query().convert() 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 # 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: if "accessURLdescriptionPage" in x:
print("url for description present") # print("url for description present")
print(x["accessURLdescriptionPage"]["value"]) # print(x["accessURLdescriptionPage"]["value"])
accessURLdescriptionUrl = x["accessURLdescriptionPage"]["value"] accessURLdescriptionUrl = x["accessURLdescriptionPage"]["value"]
desc_url = re.search(r':Q(.*)', accessURLdescriptionUrl, re.DOTALL) desc_url = re.search(r':Q(.*)', accessURLdescriptionUrl, re.DOTALL)
# print(desc_url.group(1)) # print(desc_url.group(1))
@ -360,33 +415,21 @@ def artwork():
# # print(soup.prettify()) # print the parsed data of html # # print(soup.prettify()) # print the parsed data of html
text=soup.find("div" , {"class" : "mw-parser-output"}) text=soup.find("div" , {"class" : "mw-parser-output"})
# text=soup.find_all("p") # text=soup.find_all("p")
artworkdescriptiontext=Markup(text) # text=Markup(text)
# artworkdescriptiontext.append(text)
x["text"] = text
else: else:
print("url for description absent") # print("url for description absent")
text="<p>Information not available</p>" text="<p>Information not available</p>"
artworkdescriptiontext=Markup(text) x["text"] = 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)
# print(artworkdescriptiontext)
############ right bottom LATER
# exhibitions + id to be changed # exhibitions + id to be changed
sparql.setQuery(''' sparql.setQuery('''
SELECT ?accessURLexhibitionHisPage ?authorexhibitionHisPageLabel ?dateexhibitionHisPage ?sourceexhibitionHisPage SELECT ?accessURLexhibitionHisPage ?authorexhibitionHisPageLabel ?dateexhibitionHisPage ?sourceexhibitionHisPage
WHERE WHERE
{ {
VALUES ?work {wd:Q57} VALUES ?work {wd:'''+artwork_id+'''}
?work wdt:P66 ?exhibitionHisPage. ?work wdt:P66 ?exhibitionHisPage.
OPTIONAL { ?exhibitionHisPage wdt:P4 ?accessURLexhibitionHisPage. } OPTIONAL { ?exhibitionHisPage wdt:P4 ?accessURLexhibitionHisPage. }
OPTIONAL { ?exhibitionHisPage wdt:P9 ?authorexhibitionHisPage. } OPTIONAL { ?exhibitionHisPage wdt:P9 ?authorexhibitionHisPage. }
@ -398,18 +441,34 @@ def artwork():
sparql.setReturnFormat(JSON) sparql.setReturnFormat(JSON)
artworkexhibitiondata = sparql.query().convert() artworkexhibitiondata = sparql.query().convert()
# description content from wiki # get the text from the url
artworkexhibitioncontenturl = "https://daap.bannerrepeater.org/w/index.php?title=History:"+artwork_id+"&action=render" for x in artworkexhibitiondata['results']['bindings']:
# Make a GET request to fetch the raw HTML content if "accessURLexhibitionHisPage" in x:
html_content = requests.get(artworkexhibitioncontenturl).text # print("url for description present")
# Parse the html content # print(x["accessURLexhibitionHisPage"]["value"])
soup = BeautifulSoup(html_content, "lxml") accessURLexhibitionHisPage = x["accessURLexhibitionHisPage"]["value"]
# print(soup.prettify()) # print the parsed data of html 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="<p>Information not available</p>"
# 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 ############## bottom
# copies in collection # copies in collection
@ -425,7 +484,6 @@ def artwork():
} ''') } ''')
sparql.setReturnFormat(JSON) sparql.setReturnFormat(JSON)
copiesincollection = sparql.query().convert() copiesincollection = sparql.query().convert()
# print(copiesincollection)
# related works # related works
sparql.setQuery(''' sparql.setQuery('''
@ -446,13 +504,30 @@ def artwork():
} ''') } ''')
sparql.setReturnFormat(JSON) sparql.setReturnFormat(JSON)
relatedworks = sparql.query().convert() 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(): def person():
person_id = request.args.get('id') person_id = request.args.get('id')
sparql.setQuery(''' sparql.setQuery('''
SELECT ?item ?itemLabel ?itemDescription ?propLabel ?b ?bLabel SELECT ?item ?itemLabel ?itemDescription ?propLabel ?b ?bLabel
WHERE WHERE
{ {
VALUES ?item {wd:'''+person_id+'''} VALUES ?item {wd:'''+person_id+'''}
?item ?a ?b. ?item ?a ?b.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
?prop wikibase:directClaim ?a . ?prop wikibase:directClaim ?a .
} }
@ -478,7 +551,7 @@ def person():
print(person_details) print(person_details)
sparql2.setQuery(''' sparql.setQuery('''
SELECT ?work ?workLabel ?image ?date SELECT ?work ?workLabel ?image ?date
WHERE { WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
@ -490,10 +563,10 @@ def person():
} }
ORDER BY (?workLabel) ORDER BY (?workLabel)
''') ''')
sparql2.setReturnFormat(JSON) sparql.setReturnFormat(JSON)
person_creatorof = sparql2.query().convert() person_creatorof = sparql.query().convert()
sparql3.setQuery(''' sparql.setQuery('''
SELECT ?work ?workLabel ?image ?date SELECT ?work ?workLabel ?image ?date
WHERE { WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". } SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
@ -505,8 +578,8 @@ def person():
} }
ORDER BY (?workLabel) ORDER BY (?workLabel)
''') ''')
sparql3.setReturnFormat(JSON) sparql.setReturnFormat(JSON)
person_publisherof = sparql2.query().convert() person_publisherof = sparql.query().convert()
person_url = "" person_url = ""
person_name = "the name" person_name = "the name"
@ -541,12 +614,11 @@ def about():
# print(soup.prettify()) # print the parsed data of html # print(soup.prettify()) # print the parsed data of html
text=soup.find("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/" # replaceString = "wiki/Special:Redirect/file/"
# cleanSoup = BeautifulSoup(str(text).replace("wiki/File:", replaceString)) # cleanSoup = BeautifulSoup(str(text).replace("wiki/File:", replaceString))
# for a in soup.find_all('a', href=True): # for a in soup.find_all('a', href=True):
# if a.text: # if a.text:
# print(a['href']) # print(a['href'])
@ -626,21 +698,6 @@ def codeofconduct():
######################### LOGIN ######################### LOGIN
#Goes to wikibase page #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 # ALL NAME

203
templates/artwork.html

@ -1,9 +1,10 @@
{% extends "layout.html" %} {% extends "layout.html" %}
{% block content %} {% block content %}
<div> <div>
<!-- Artwork title and navigation --> <!-- ARTWORK TITLE AND NAVIGATION -->
<div> <div>
<!-- ARTWORK label in rectangle --> <!-- ARTWORK label in rectangle -->
<div class="artwork-box"> <div class="artwork-box">
@ -27,37 +28,102 @@
<!-- NAVIGATION HERE? --> <!-- NAVIGATION HERE? -->
<div class="artwork-nav"> <div class="artwork-nav">
<div class="artwork-nav-label active">ABOUT THIS WORK</div> <div class="artwork-nav-label active">ABOUT THIS WORK</div>
<div class="artwork-nav-label">RELATIONSHIPS</div> <!-- <div class="artwork-nav-label">RELATIONSHIPS</div> -->
<div class="artwork-nav-label">LISTS</div> <!-- <div class="artwork-nav-label">LISTS</div> -->
<div class="artwork-nav-label"><a class="det-record" target="_blank" href="https://daap.bannerrepeater.org/wiki/Item:{{ artwork_id }}">DETAILED RECORD</a></div> <div class="artwork-nav-label"><a class="det-record" target="_blank" href="https://daap.bannerrepeater.org/wiki/Item:{{ artwork_id }}">DETAILED RECORD</a></div>
</div> </div>
</div> </div>
<!-- The content in 3 divs displayed or not (detailed revord is out)-->
<!-- about or relationships or lists or detailed record --> <!-- ABOUT -->
<div class="artwork-about"> <div class="artwork-about">
<!-- left --> <!-- ARTWORK LEFT COLUMN -->
<div class="artwork-leftcolumn"> <div class="artwork-leftcolumn">
<!-- img - I am unsure how to handle the thing to go through the different pictures --> <!-- ARTWORK IMAGES -->
<div class="artwork-about-img"> <div class="artwork-about-img">
{% if artworkimages['results']['bindings']==[] %} {% if artworkimages['results']['bindings']==[] %}
<img class="artwork-about-imgs" src="{{ url_for('static', filename='/imgs/Icons/placeholder_no-image2.png') }}"> <img class="artwork-about-imgs" src="{{ url_for('static', filename='/imgs/Icons/placeholder_no-image2.png') }}">
{% else %} {% else %}
{% for x in artworkimages["results"]["bindings"] %} {% for x in artworkimages['results']['bindings'] %}
<img class="artwork-about-imgs" src='{{ x["image"]["value"] | replace("wiki/File:","wiki/Special:Redirect/file/") }}'> {% if loop.index <= 1 %}
{% if "image" in x %}
<img class="artwork-about-imgs" src='{{ x["image"]["value"] | replace("wiki/File:","wiki/Special:Redirect/file/") }}'>
{% endif %}
{% endif %}
{% endfor %} {% endfor %}
{% endif %} {% endif %}
</div> </div>
<!-- other stuff like downloads, absent for now --> <!-- other stuff like downloads, absent for now -->
<div></div>
</div>
<!-- right <!-- DOWNLOADS AND LINKS -->
<div class="artwork-rightcolumn"> --> <div>
<!-- contributors / date / publishers --> {% if artworklinksanddownloads['results']['bindings']==[] %}
{% else %}
{% for x in artworklinksanddownloads['results']['bindings'] %}
<p class="label-item">DOWNLOADS AND LINKS</p>
{% if 'DownloadDigitalFacsimile' in x %}
<div>
<a target="_blank" href="{{ x['DownloadDigitalFacsimile']['value'] }}"><img src="{{ url_for('static', filename='/imgs/Icons/icn_download.svg') }}"></a>
<span>Download digital facsimile</span>
</div>
{% endif %}
{% if 'DigitalFacsimileExternalLink' in x %}
<div>
<a target="_blank" href="{{ x['DigitalFacsimileExternalLink']['value'] }}"><img src="{{ url_for('static', filename='/imgs/Icons/icn_external_link.svg') }}"></a>
<span>External digital facsimile linl</span>
</div>
{% endif %}
{% if 'DigitalFacsimileExternalLink2' in x %}
<div>
<a target="_blank" href="{{ x['DigitalFacsimileExternalLink2']['value'] }}"><img src="{{ url_for('static', filename='/imgs/Icons/icn_external_link.svg') }}"></a>
<span>External digital facsimile link 2</span>
</div>
{% endif %}
{% endfor %}
{% endif %}
</div>
<!-- OTHER DIGITAL ARTEFACTS -->
<div>
{% if artworkartefacts['results']['bindings']==[] %}
<p class="label-item">OTHER DIGTAL ARTEFACTS</p>
<!-- video images audio -->
{% for x in artworkartefacts['results']['bindings'] %}
{{ x }}
{% endfor %}
{% endif %}
</div>
<!-- DISTRIBUTOR LINKS -->
<div>
{% if artworkdistributorlinks['results']['bindings']==[] %}
{% else %}
<p class="label-item">DISTRIBUTOR LINKS</p>
{% for x in artworkdistributorlinks['results']['bindings'] %}
{% if 'distributorLinks' in x %}
<div>
<img src="{{ url_for('static', filename='/imgs/Icons/icn_external_link.svg') }}">
<a target="_blank" href="{{ x['distributorLinks']['value'] }}">{{ x['distributorLinks']['value'] }}</a>
</div>
{% endif %}
{% endfor %}
</p>
{% endif %}
</div>
</div>
</div>
<!-- RIGHT COLUMN -->
<div class="artwork-rightcolumn">
<!-- RIGHT TOP -->
<!-- contributors --> <!-- contributors -->
<div class="artwork-rightcolumn-top-contributors"> <div class="artwork-rightcolumn-top-contributors">
<p class="label-item">CONTRIBUTORS</p> <p class="label-item">CONTRIBUTORS</p>
@ -111,31 +177,88 @@
</div> </div>
</div> </div>
</div> </div>
<div class="artwork-about-bottom"> <div class="artwork-about-bottom">
<!-- description --> <!-- description -->
<!-- if there is a description add description here --> <!-- if there is a description add description here -->
<div> {% if artworkdescriptiondata['results']['bindings']==[] %}
<span class="label-item">DESCRIPTION</span> {% else %}
<!-- For loop -->
{% for x in artworkdescriptiondata['results']['bindings'] %}
<div>
<p class="label-item">DESCRIPTION</p>
<!-- left part with the description text already coming in a div from wiki--> <!-- left part with the description text already coming in a div from wiki-->
{{ artworkdescriptiontext }} <div>
{{ x["text"] | safe }}
</div>
<!-- right ride with author etc LATER--> <!-- right ride with author etc LATER-->
<!-- <div> --> <div>
<!-- <span class="label-item">AUTHOR</span> --> {% if "authordescriptionPageLabel" in x %}
<p class="label-item">AUTHOR</p>
<p>{{ x['authordescriptionPageLabel']['value'] }}</p>
{% endif %}
<!-- if there is an author name then add here otherwise info non available --> <!-- if there is an author name then add here otherwise info non available -->
<!-- <span class="label-item">SOURCE</span> -->
{% if "sourcedescriptionPage" in x %}
<p class="label-item">SOURCE</p>
<p>{{ x["sourcedescriptionPage"]["value"]}} </p>
<!-- if there is a source name then add here otherwise info non available --> <!-- if there is a source name then add here otherwise info non available -->
<!-- <span class="label-item">DATE</span> --> {% endif %}
{% if "datedescriptionPage" in x %}
<p class="label-item">DATE</p>
<p>{{ x["datedescriptionPage"]["value"] | replace("T00:00:00Z", "") }}</p>
{% endif %}
<!-- if there is a date add here otherwise info non available--> <!-- if there is a date add here otherwise info non available-->
<!-- </div> --> </div>
</div> </div>
{% endfor %}
{% endif %}
<!-- end description loop --> <!-- end description loop -->
<!-- exhibition and distribution history loop--> <!-- exhibition and distribution history loop-->
<div></div> <!-- if exhibition in, then do show that -->
{% if artworkexhibitiondata['results']['bindings']==[] %}
{% else %}
{% for x in artworkexhibitiondata['results']['bindings'] %}
<div>
<p class="label-item">EXHIBITION AND DISTRIBUTION HISTORY</p>
<div>
{{ artworkexhibitiontext | safe }}
</div>
<!-- right ride with author etc LATER-->
<div>
<p class="label-item">AUTHOR</p>
<!-- if there is an author name then add here otherwise info non available -->
{% if "authorexhibitionHisPageLabel" in x %}
<p>{{ x["authorexhibitionHisPageLabel"]["value"]}} </p>
{% endif %}
<p class="label-item">SOURCE</p>
<!-- if there is a source name then add here otherwise info non available -->
{% if "sourceexhibitionHisPage" in x%}
<p>{{ x["sourceexhibitionHisPage"]["value"]}} </p>
{% endif %}
<p class="label-item">DATE</p>
<!-- if there is a date add here otherwise info non available-->
{% if "dateexhibitionHisPage" in x%}
<p>{{ x["dateexhibitionHisPage"]["value"] | replace("T00:00:00Z", "") }} </p>
{% endif %}
</div>
</div>
{% endfor %}
{% endif %}
<!-- end exhibition loop --> <!-- end exhibition loop -->
<!-- end of right column --> <!-- end of right column -->
@ -143,10 +266,36 @@
<!-- end of about --> <!-- end of about -->
</div> </div>
<!-- relationships --> <!-- lists DESIGN IF NO LISTS TO BE CLARIFIE-->
<div></div> <div class="artwork-nav-label">LISTS</div>
<!-- lists --> <div class="artwork-lists">
<div></div> {% if artworklists['results']['bindings']==[] %}
<p>The artwork isn't featured in any lists yet</p>
{% else %}
<p>This artwork is featured in the following lists: </p>
{% for x in artworklists['results']['bindings'] %}
<div>
<div class="artwork-lists-img">
{% if "image" in x %}
<img src="x['image']['value']">
{% else %}
<img src="{{ url_for('static', filename='/imgs/Icons/placeholder_no-image2.png') }}">
{% endif %}
</div>
<div class="artwork-lists-title">
{% if "listLabel" in x %}
{{ x['listLabel']['value'] }}
{% endif %}
</div>
<div class="artwork-lists-works-number">
placeholder for number of artworks in list
</div>
</div>
{% endfor %}
{% endif %}
</div>
<!-- copies in collections --> <!-- copies in collections -->
<div class="artwork-copieswrapper"> <div class="artwork-copieswrapper">

Loading…
Cancel
Save