Browse Source

more work on artwork page

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

197
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="<p>Information not available</p>"
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="<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
# 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

203
templates/artwork.html

@ -1,9 +1,10 @@
{% extends "layout.html" %}
{% block content %}
<div>
<!-- Artwork title and navigation -->
<!-- ARTWORK TITLE AND NAVIGATION -->
<div>
<!-- ARTWORK label in rectangle -->
<div class="artwork-box">
@ -27,37 +28,102 @@
<!-- NAVIGATION HERE? -->
<div class="artwork-nav">
<div class="artwork-nav-label active">ABOUT THIS WORK</div>
<div class="artwork-nav-label">RELATIONSHIPS</div>
<div class="artwork-nav-label">LISTS</div>
<!-- <div class="artwork-nav-label">RELATIONSHIPS</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>
</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">
<!-- left -->
<!-- ARTWORK LEFT COLUMN -->
<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">
{% if artworkimages['results']['bindings']==[] %}
<img class="artwork-about-imgs" src="{{ url_for('static', filename='/imgs/Icons/placeholder_no-image2.png') }}">
{% else %}
{% for x in artworkimages["results"]["bindings"] %}
<img class="artwork-about-imgs" src='{{ x["image"]["value"] | replace("wiki/File:","wiki/Special:Redirect/file/") }}'>
{% for x in artworkimages['results']['bindings'] %}
{% 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 %}
{% endif %}
</div>
<!-- other stuff like downloads, absent for now -->
<div></div>
<!-- DOWNLOADS AND LINKS -->
<div>
{% 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
<div class="artwork-rightcolumn"> -->
<!-- contributors / date / publishers -->
<!-- RIGHT COLUMN -->
<div class="artwork-rightcolumn">
<!-- RIGHT TOP -->
<!-- contributors -->
<div class="artwork-rightcolumn-top-contributors">
<p class="label-item">CONTRIBUTORS</p>
@ -111,31 +177,88 @@
</div>
</div>
</div>
<div class="artwork-about-bottom">
<!-- description -->
<!-- if there is a description add description here -->
<div>
<span class="label-item">DESCRIPTION</span>
{% if artworkdescriptiondata['results']['bindings']==[] %}
{% 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-->
{{ artworkdescriptiontext }}
<div>
{{ x["text"] | safe }}
</div>
<!-- right ride with author etc LATER-->
<!-- <div> -->
<!-- <span class="label-item">AUTHOR</span> -->
<div>
{% 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 -->
<!-- <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 -->
<!-- <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-->
<!-- </div> -->
</div>
</div>
{% endfor %}
{% endif %}
<!-- end description 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 of right column -->
@ -143,10 +266,36 @@
<!-- end of about -->
</div>
<!-- relationships -->
<div></div>
<!-- lists -->
<div></div>
<!-- lists DESIGN IF NO LISTS TO BE CLARIFIE-->
<div class="artwork-nav-label">LISTS</div>
<div class="artwork-lists">
{% 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 -->
<div class="artwork-copieswrapper">

Loading…
Cancel
Save