Flask application repository for Banner Repeater's DAAP (Digital Archive of Artists Publishing). SPARQL queries by Lozana Rossenova, CSS and JS by Joana Chicau, python and Jinja by Julie Boschat-Thorez. See https://daap.network
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

1274 lines
41 KiB

# encoding=utf8
# # # # # # # # # # # # # # # # # # # # # # # #
# REQUIREMENTS
# # # # # # # # # # # # # # # # # # # # # # # #
from flask import send_file, Flask, Response, url_for, render_template, Markup, jsonify, redirect, request, flash, session, make_response
import requests
from SPARQLWrapper import SPARQLWrapper, JSON
import json
# import pandas as pd
# ##### IMPORTS FOR TEST WIKIPAGE
from lxml import html
from bs4 import BeautifulSoup
import re
# # # # # # # # # # # # # # # # # # # # # # # #
# GETTING STARTED
# # # # # # # # # # # # # # # # # # # # # # # #
app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates")
app.config['SEND_FILE_MAX_AGE_DEFAULT'] = 0
app.jinja_env.add_extension('jinja2.ext.loopcontrols')
# # # # # # # # # # # # # # # # # # # # # # # #
# GETTING WIKIBASE DATA
# # # # # # # # # # # # # # # # # # # # # # # #
sparql = SPARQLWrapper("https://query.daap.bannerrepeater.org/proxy/wdqs/bigdata/namespace/wdq/sparql")
# # # # # # # # # # # # # # # # # # # # # # # #
# PAGES
# # # # # # # # # # # # # # # # # # # # # # # #
@app.route("/")
def home():
sparql.setQuery('''
SELECT ?work ?workLabel ?image ?date ?dateadded WHERE {
{
SELECT ?work ?workLabel (SAMPLE(?date) AS ?date)
WHERE
{ ?work wdt:P1 wd:Q1;
wdt:P13 ?date.
FILTER(?work != wd:Q57)
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?work ?workLabel
ORDER BY ?workLabel
}
{
SELECT ?work ?workLabel (SAMPLE(?image) AS ?image)
WHERE
{ ?work wdt:P1 wd:Q1;
p:P90 ?statement.
?statement ps:P90 ?image;
pq:P54 wd:Q90.
FILTER(?work != wd:Q57)
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?work ?workLabel
ORDER BY ?workLabel
}
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?work wdt:P1 wd:Q1;
wdt:P87 ?dateadded.
FILTER(?work != wd:Q57)
}
ORDER BY DESC (?dateadded)
LIMIT 12
''')
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
ImagesBanner = []
# print(results)
for publication in results["results"]["bindings"]:
publication_title = publication["workLabel"]["value"]
publication_uri = publication["work"]["value"]
#if key exists
if "date" in publication:
publication_date = publication["date"]["value"]
if "image" in publication:
publication_image = publication["image"]["value"]
ImagesBanner.append(publication_image)
ImagesBanner = ImagesBanner[-12:]
return render_template('home.html', results=results, ImagesBanner=ImagesBanner)
@app.route("/browsethearchive")
def browsethearchive():
sparql.setQuery('''
SELECT ?work ?workLabel ?image ?date WHERE {
{
SELECT ?work ?workLabel (SAMPLE(?date) AS ?date)
WHERE
{ ?work wdt:P1 wd:Q1;
wdt:P13 ?date.
FILTER(?work != wd:Q57)
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?work ?workLabel
ORDER BY ?workLabel
}
?work wdt:P1 wd:Q1.
OPTIONAL {?work p:P90 ?statement.
?statement ps:P90 ?image;
pq:P54 wd:Q90.}
FILTER(?work != wd:Q57)
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
ORDER BY ?workLabel
''')
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
# print(results)
for publication in results["results"]["bindings"]:
publication_title = publication["workLabel"]["value"]
publication_uri = publication["work"]["value"]
#if key exists
if "date" in publication:
publication_date = publication["date"]["value"]
if "image" in publication:
publication_image = publication["image"]["value"]
return render_template('browsethearchive.html', results=results)
@app.route("/browsebycategory")
def browsebycategory():
return render_template('browsebycategory.html')
##########################
# CATEGORIES TO BE BROWSED
#########################
######################### ARTIST INDEX
@app.route("/artistsindex")
def artistsindex():
sparql.setQuery('''
SELECT ?creators ?creatorsLabel ?creatorsAltLabel ?creatorsDescription
WHERE {
{
SELECT ?creators (COUNT(DISTINCT ?a) AS ?count) WHERE {
?a ?prop ?creators .
?a wdt:P1 ?work .
BIND (wdt:P9 AS ?prop) .
BIND (wd:Q1 AS ?work) .
} GROUP BY ?creators
} .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
FILTER (?creators !=wd:Q82)
}
ORDER BY DESC(?count) ?creatorsLabel
''')
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
return render_template('artistsindex.html', results=results)
######################### PUBLISHERS INDEX
@app.route("/publishersindex")
def publishersindex():
sparql.setQuery('''
SELECT ?publishers ?publishersLabel ?publishersAltLabel ?publishersDescription WHERE {
{
SELECT ?publishers (COUNT(DISTINCT ?a) AS ?count) WHERE {
?a ?prop ?publishers .
?a wdt:P1 ?work .
BIND (wdt:P10 AS ?prop) .
BIND (wd:Q1 AS ?work) .
} GROUP BY ?publishers
} .
SERVICE wikibase:label {
bd:serviceParam wikibase:language "en" .
}
FILTER(?publishers != wd:Q83)
FILTER(?publishers != wd:Q71)
}
ORDER BY DESC(?count) ?publishersLabel
''')
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
return render_template('publishersindex.html', results=results)
######################### SELF PUBLISHED INDEX
@app.route("/selfpublishedindex")
def selfpublishedindex():
sparql.setQuery('''
SELECT ?work ?workLabel ?image ?date
WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?work wdt:P1 wd:Q1;
wdt:P10 wd:Q71.
OPTIONAL {?work p:P90 ?statement.
?statement ps:P90 ?image;
pq:P54 wd:Q90.}
OPTIONAL { ?work wdt:P13 ?date. }
FILTER(?work != wd:Q57)
}
''')
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
return render_template('selfpublishedindex.html', results=results)
######################### ZINES INDEX
@app.route("/zinesindex")
def zinesindex():
sparql.setQuery('''
SELECT ?work ?workLabel ?image ?date
WHERE {
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
?work wdt:P1 wd:Q1;
wdt:P16 wd:Q152.
OPTIONAL {?work p:P90 ?statement.
?statement ps:P90 ?image;
pq:P54 wd:Q90.}
OPTIONAL { ?work wdt:P13 ?date. }
FILTER(?work != wd:Q57)
}
ORDER BY ?workLabel
''')
sparql.setReturnFormat(JSON)
results = sparql.query().convert()
# print(results)
return render_template('zinesindex.html', results=results)
##########################
# DETAILED INDIVIDUAL PAGES
#########################
######################### ARTWORK
@app.route("/artwork", methods=['GET'])
def artwork():
artwork_id = request.args.get('id')
# Artwork Intro / Top of the page
sparql.setQuery('''
SELECT ?work ?workLabel ?workDescription ?itemtypeLabel
{
VALUES ?work {wd:'''+artwork_id+'''}
?work wdt:P1 ?itemtype.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
''')
sparql.setReturnFormat(JSON)
artworkintro = sparql.query().convert()
# Image(s)
# query for later
sparql.setQuery('''
SELECT ?image ?depictsLabel ?licenseLabel
WHERE
{
VALUES ?work {wd:'''+artwork_id+'''}
?work 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)
artworkimages = sparql.query().convert()
# 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()
# Other digital artefacts
sparql.setQuery('''
SELECT ?ImageFile ?AudioFile ?VideoFile
WHERE
{
{
SELECT ?ImageFile WHERE {
4 years ago
VALUES ?work {wd:'''+artwork_id+'''}
OPTIONAL {?work p:P35 ?statement.
?statement ps:P35 ?ImageFile;
pq:P16 wd:Q85.}
}}
{
SELECT ?AudioFile WHERE {
4 years ago
VALUES ?work {wd:'''+artwork_id+'''}
OPTIONAL {?work p:P35 ?statement.
?statement ps:P35 ?AudioFile;
pq:P16 wd:Q28.}
}}
{
SELECT ?VideoFile WHERE {
4 years ago
VALUES ?work {wd:'''+artwork_id+'''}
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
sparql.setQuery('''
SELECT DISTINCT ?creators ?creatorsLabel (group_concat(?creatorRolesLabel; separator="; ") as ?role)
WHERE
{
VALUES ?work {wd:'''+artwork_id+'''}
?work wdt:P9 ?creators.
OPTIONAL { ?work p:P9 ?statement1.
?statement1 ps:P9 ?creators;
pq:P49 ?creatorRoles. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en".
?creators rdfs:label ?creatorsLabel.
?creatorRoles rdfs:label ?creatorRolesLabel. }
}
GROUP BY ?creators ?creatorsLabel
ORDER BY ?creatorsLabel
''')
sparql.setReturnFormat(JSON)
artworkcontributors = sparql.query().convert()
# date
sparql.setQuery('''
SELECT ?date ?sourceLabel
WHERE
{
VALUES ?work {wd:'''+artwork_id+'''}
?work wdt:P13 ?date.
OPTIONAL { ?work p:P13 ?statement1.
?statement1 ps:P13 ?date;
pq:P50 ?source. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en".}
}
''')
sparql.setReturnFormat(JSON)
artworkdate = sparql.query().convert()
# publishers
sparql.setQuery('''
SELECT DISTINCT ?publishers ?publishersLabel (group_concat(?publishersRolesLabel; separator="; ") as ?role)
WHERE
{
VALUES ?work {wd:'''+artwork_id+'''}
?work wdt:P10 ?publishers.
OPTIONAL { ?work p:P10 ?statement1.
?statement1 ps:P10 ?publishers;
pq:P49 ?creatorRoles. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en".
?publishers rdfs:label ?publishersLabel.
?publishersRoles rdfs:label ?publishersRolesLabel. }
}
GROUP BY ?publishers ?publishersLabel
ORDER BY ?publishersLabel
''')
sparql.setReturnFormat(JSON)
artworkpublisher = sparql.query().convert()
#####right middle
# description + id to be changed
sparql.setQuery('''
SELECT ?accessURLdescriptionPage ?authordescriptionPageLabel ?datedescriptionPage ?sourcedescriptionPage
WHERE
{
VALUES ?work {wd:'''+artwork_id+'''}
?work wdt:P65 ?descriptionPage.
OPTIONAL { ?descriptionPage wdt:P4 ?accessURLdescriptionPage. }
{
SELECT DISTINCT ?descriptionPage (group_concat(?authorsdescriptionPageLabel; separator="; ") as ?authordescriptionPageLabel)
WHERE
{
VALUES ?work {wd:'''+artwork_id+'''}
?work wdt:P65 ?descriptionPage.
OPTIONAL { ?descriptionPage wdt:P9 ?authorsdescriptionPage. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en".
?authorsdescriptionPage rdfs:label ?authorsdescriptionPageLabel.
?authordescriptionPage rdfs:label ?authordescriptionPageLabel. }
}
GROUP BY ?descriptionPage
ORDER BY ?descriptionPage
}
OPTIONAL { ?descriptionPage wdt:P13 ?datedescriptionPage. }
OPTIONAL { ?descriptionPage wdt:P50 ?sourcedescriptionPage. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
''')
sparql.setReturnFormat(JSON)
artworkdescriptiondata = sparql.query().convert()
print(artworkdescriptiondata)
for x in artworkdescriptiondata['results']['bindings']:
if "accessURLdescriptionPage" in x:
accessURLdescriptionUrl = x["accessURLdescriptionPage"]["value"]
desc_url = re.search(r':Q(.*)', accessURLdescriptionUrl, re.DOTALL)
desc_id=desc_url.group(1)
# # get the description content from wiki
artworkdescriptioncontenturl = "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(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")
# text=Markup(text)
# artworkdescriptiontext.append(text)
x["text"] = text
else:
# print("url for description absent")
text="<p>Information not available</p>"
x["text"] = text
# exhibitions + id to be changed
sparql.setQuery('''
SELECT ?accessURLexhibitionHisPage ?authorexhibitionHisPageLabel ?dateexhibitionHisPage ?sourceexhibitionHisPage
WHERE
{
VALUES ?work {wd:'''+artwork_id+'''}
?work wdt:P66 ?exhibitionHisPage.
OPTIONAL { ?exhibitionHisPage wdt:P4 ?accessURLexhibitionHisPage. }
{ SELECT DISTINCT ?exhibitionHisPage (group_concat(?authorsexhibitionHisPageLabel; separator="; ") as ?authorexhibitionHisPageLabel)
WHERE
{
VALUES ?work {wd:'''+artwork_id+'''}
?work wdt:P66 ?exhibitionHisPage.
OPTIONAL { ?exhibitionHisPage wdt:P9 ?authorsexhibitionHisPage. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en".
?authorsexhibitionHisPage rdfs:label ?authorsexhibitionHisPageLabel.
?authorexhibitionHisPage rdfs:label ?authorexhibitionHisPageLabel. }
}
GROUP BY ?exhibitionHisPage
ORDER BY ?exhibitionHisPage
}
OPTIONAL { ?exhibitionHisPage wdt:P13 ?dateexhibitionHisPage. }
OPTIONAL { ?exhibitionHisPage wdt:P50 ?sourceexhibitionHisPage. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
''')
sparql.setReturnFormat(JSON)
artworkexhibitiondata = sparql.query().convert()
# get the text from the url
for x in artworkexhibitiondata['results']['bindings']:
if "accessURLexhibitionHisPage" in x:
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
############## bottom
# copies in collection
sparql.setQuery('''
SELECT ?copiesCollections ?copiesCollectionsLabel ?collection ?collectionLabel ?image
WHERE
{
VALUES ?work {wd:'''+artwork_id+'''}
?work wdt:P43 ?copiesCollections.
?copiesCollections wdt:P47 ?collection.
OPTIONAL { ?collection wdt:P90 ?image. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
} ''')
sparql.setReturnFormat(JSON)
copiesincollection = sparql.query().convert()
# related works
sparql.setQuery('''
SELECT ?relatedWorks ?relatedWorksLabel ?image ?daterelatedWorks
WHERE {
{
SELECT ?relatedWorks ?relatedWorksLabel (SAMPLE(?daterelatedWorks) AS ?daterelatedWorks)
WHERE
{ VALUES ?work {wd:'''+artwork_id+'''}
?work wdt:P44 ?relatedWorks.
OPTIONAL {?relatedWorks wdt:P13 ?daterelatedWorks.}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?relatedWorks ?relatedWorksLabel
ORDER BY ?relatedWorksLabel
}
{
SELECT ?relatedWorks ?relatedWorksLabel (SAMPLE(?image) AS ?image)
WHERE
{ VALUES ?work {wd:'''+artwork_id+'''}
?work wdt:P44 ?relatedWorks.
OPTIONAL {?relatedWorks wdt:P90 ?image.}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?relatedWorks ?relatedWorksLabel
ORDER BY ?relatedWorksLabel
}
}
''')
sparql.setReturnFormat(JSON)
relatedworks = sparql.query().convert()
# 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:P90 ?image.}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en".}
}
''')
sparql.setReturnFormat(JSON)
artworklists = sparql.query().convert()
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)
3 years ago
######################### 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="<p>Information not available</p>"
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
@app.route("/item", methods=['GET'])
def item():
item_id = request.args.get('id')
# Intro
sparql.setQuery('''
SELECT ?item ?itemLabel ?itemDescription ?itemtypeLabel
{
VALUES ?item {wd:'''+item_id+'''}
?item wdt:P1 ?itemtype.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
''')
sparql.setReturnFormat(JSON)
itemintro = sparql.query().convert()
# image
sparql.setQuery('''
SELECT ?image ?depictsLabel ?licenseLabel
WHERE
{
VALUES ?item {wd:'''+item_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)
itemimage = sparql.query().convert()
# official website
sparql.setQuery('''
SELECT ?website
WHERE
{
VALUES ?item {wd:'''+item_id+'''}
?item wdt:P61 ?website.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
''')
sparql.setReturnFormat(JSON)
itemwebsite = sparql.query().convert()
# wikidata id
sparql.setQuery('''
SELECT ?WikidataID
WHERE
{
VALUES ?item {wd:'''+item_id+'''}
?item wdt:P3 ?WikidataID.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
''')
sparql.setReturnFormat(JSON)
itemwikidataID = sparql.query().convert()
# viaf ID
sparql.setQuery('''
SELECT ?VIAFID
WHERE
{
VALUES ?item {wd:'''+item_id+'''}
?item wdt:P80 ?VIAFID.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
''')
sparql.setReturnFormat(JSON)
itemviafID = sparql.query().convert()
# PERSON gender
# for test:Q82}
sparql.setQuery('''
SELECT ?genderLabel
WHERE
{
VALUES ?item {wd:'''+item_id+'''}
?item wdt:P86 ?gender.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
''')
sparql.setReturnFormat(JSON)
persongender = sparql.query().convert()
# PERSON pronouns
sparql.setQuery('''
SELECT ?pronounLabel
WHERE
{
VALUES ?item {wd:'''+item_id+'''}
?item wdt:P85 ?pronoun.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
''')
sparql.setReturnFormat(JSON)
personpronouns = sparql.query().convert()
# ORGANISATION location
sparql.setQuery('''
SELECT ?locationLabel
WHERE
{
VALUES ?item {wd:'''+item_id+'''}
?item wdt:P83 ?location.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
''')
sparql.setReturnFormat(JSON)
orglocation = sparql.query().convert()
# ORGANISATION country
sparql.setQuery('''
SELECT ?countryLabel
WHERE
{
VALUES ?item {wd:'''+item_id+'''}
?item wdt:P84 ?country.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
''')
sparql.setReturnFormat(JSON)
orgcountry = sparql.query().convert()
# COLLECTIVE MEMBERS
# for test:Q309}
sparql.setQuery('''
SELECT ?members ?membersLabel
WHERE
{
VALUES ?item {wd:'''+item_id+'''}
?item wdt:P74 ?members.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
''')
sparql.setReturnFormat(JSON)
collectivemembers = sparql.query().convert()
# PERSON biography
sparql.setQuery('''
SELECT ?accessURLbioPage ?authorBioPageLabel ?dateBioPage ?sourceBioPageLabel
WHERE
{
VALUES ?item {wd:'''+item_id+'''}
?item wdt:P67 ?bioPage.
OPTIONAL { ?bioPage wdt:P4 ?accessURLbioPage. }
OPTIONAL { ?bioPage wdt:P9 ?authorBioPage. }
OPTIONAL { ?bioPage wdt:P13 ?dateBioPage. }
OPTIONAL { ?bioPage wdt:P50 ?sourceBioPage. }
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
''')
sparql.setReturnFormat(JSON)
personbiography = sparql.query().convert()
for x in personbiography['results']['bindings']:
if "accessURLbioPage" in x:
accessURLbioURL = x["accessURLbioPage"]["value"]
desc_url = re.search(r':Q(.*)', accessURLbioURL, re.DOTALL)
desc_id=desc_url.group(1)
# # get the description content from wiki
personbiocontenturl = "https://daap.bannerrepeater.org/w/index.php?title=Biography:Q"+desc_id+"&action=render"
# # Make a GET request to fetch the raw HTML content
html_content = requests.get(personbiocontenturl).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="<p>Information not available</p>"
x["text"] = text
# COLLECTIVE AND INSTITUTION DESCRIPTION
sparql.setQuery('''
SELECT ?accessURLdescriptionPage ?authordescriptionPageLabel ?datedescriptionPage ?sourcedescriptionPageLabel
WHERE
{
VALUES ?item {wd:'''+item_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)
colorgdescription = sparql.query().convert()
for x in colorgdescription['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
itemdesccontenturl = "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(itemdesccontenturl).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="<p>Information not available</p>"
x["text"] = text
# creator of
sparql.setQuery('''
SELECT ?Works ?WorksLabel ?image ?dateWorks
WHERE {
{
SELECT ?Works ?WorksLabel (SAMPLE(?dateWorks) AS ?dateWorks)
WHERE
{
VALUES ?item {wd:'''+item_id+'''}
?Works wdt:P1 wd:Q1;
wdt:P9 ?item;
wdt:P13 ?dateWorks.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?Works ?WorksLabel
ORDER BY ?WorksLabel
}
{
SELECT ?Works ?WorksLabel (SAMPLE(?image) AS ?image)
WHERE
{
VALUES ?item {wd:'''+item_id+'''}
?Works wdt:P1 wd:Q1;
wdt:P9 ?item.
OPTIONAL {?Works wdt:P90 ?image.}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?Works ?WorksLabel
ORDER BY ?WorksLabel
}
}
''')
sparql.setReturnFormat(JSON)
item_creatorof = sparql.query().convert()
# publisher of
sparql.setQuery('''
SELECT ?Works ?WorksLabel ?image ?dateWorks
WHERE {
{
SELECT ?Works ?WorksLabel (SAMPLE(?dateWorks) AS ?dateWorks)
WHERE
{
VALUES ?item {wd:'''+item_id+'''}
?Works wdt:P1 wd:Q1;
wdt:P10 ?item;
wdt:P13 ?dateWorks.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?Works ?WorksLabel
ORDER BY ?WorksLabel
}
{
SELECT ?Works ?WorksLabel (SAMPLE(?image) AS ?image)
WHERE
{
VALUES ?item {wd:'''+item_id+'''}
?Works wdt:P1 wd:Q1;
wdt:P10 ?item.
OPTIONAL {?Works wdt:P90 ?image.}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?Works ?WorksLabel
ORDER BY ?WorksLabel
}
}
''')
sparql.setReturnFormat(JSON)
item_publisherof = sparql.query().convert()
# commissioned
sparql.setQuery('''
SELECT ?Works ?WorksLabel ?image ?dateWorks
WHERE {
{
SELECT ?Works ?WorksLabel (SAMPLE(?dateWorks) AS ?dateWorks)
WHERE
{
VALUES ?item {wd:'''+item_id+'''}
?Works wdt:P1 wd:Q1;
wdt:P14 ?item;
wdt:P13 ?dateWorks.
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?Works ?WorksLabel
ORDER BY ?WorksLabel
}
{
SELECT ?Works ?WorksLabel (SAMPLE(?image) AS ?image)
WHERE
{
VALUES ?item {wd:'''+item_id+'''}
?Works wdt:P1 wd:Q1;
wdt:P14 ?item.
OPTIONAL {?Works wdt:P90 ?image.}
SERVICE wikibase:label { bd:serviceParam wikibase:language "en". }
}
GROUP BY ?Works ?WorksLabel
ORDER BY ?WorksLabel
}
}
''')
sparql.setReturnFormat(JSON)
item_commissioned = sparql.query().convert()
return render_template("item.html", item_id=item_id, item_creatorof=item_creatorof, itemwebsite=itemwebsite, itemwikidataID=itemwikidataID, itemviafID=itemviafID, item_publisherof=item_publisherof, item_commissioned=item_commissioned, itemintro=itemintro, itemimage=itemimage, personbiography=personbiography, persongender=persongender, personpronouns=personpronouns, collectivemembers=collectivemembers, orglocation=orglocation, orgcountry=orgcountry, colorgdescription=colorgdescription)
######################### ORGANISATION
# @app.route("/organisation", methods=['GET'])
# def organisation():
# org_id = request.args.get('id')
# return render_template("organisation.html")
#########################
# PAGES FROM WIKI
#########################
######################### ABOUT
@app.route("/about")
def about():
url="https://daap.bannerrepeater.org/w/index.php?title=About&action=render"
# Make a GET request to fetch the raw HTML content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
# print(soup.prettify()) # print the parsed data of html
text=soup.find("html")
# 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'])
# replace src from img zith href from a href and remove the a
text=Markup(text)
return render_template('about.html', text=text)
######################### UPLOAD
@app.route("/upload")
def upload():
url="https://daap.bannerrepeater.org/w/index.php?title=Upload&action=render"
# Make a GET request to fetch the raw HTML content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
# print(soup.prettify()) # print the parsed data of html
text=soup.find("html")
text=Markup(text)
return render_template('upload.html', text=text)
# #################### TEAM
@app.route("/team")
def team():
url="https://daap.bannerrepeater.org/w/index.php?title=Team&action=render"
# Make a GET request to fetch the raw HTML content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
# print(soup.prettify()) # print the parsed data of html
text=soup.find("html")
text=Markup(text)
return render_template('team.html', text=text)
# #################### CASE STUDY
@app.route("/casestudy")
def casestudy():
url="https://daap.bannerrepeater.org/w/index.php?title=Carolee_Schneemann_case_study&action=render"
# Make a GET request to fetch the raw HTML content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
# print(soup.prettify()) # print the parsed data of html
text=soup.find("html")
text=Markup(text)
return render_template('casestudy.html', text=text)
# #################### CODE OF CONDUCT
@app.route("/codeofconduct")
def codeofconduct():
url="https://daap.bannerrepeater.org/w/index.php?title=Code_of_Conduct&action=render"
# Make a GET request to fetch the raw HTML content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
# print(soup.prettify()) # print the parsed data of html
text=soup.find("html")
text=Markup(text)
return render_template('codeofconduct.html', text=text)
# #################### SEARCH TOOLS
@app.route("/searchtools")
def searchtools():
url="https://daap.bannerrepeater.org/w/index.php?title=Search_Tools&action=render"
# Make a GET request to fetch the raw HTML content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
# print(soup.prettify()) # print the parsed data of html
text=soup.find("html")
text=Markup(text)
return render_template('searchtools.html', text=text)
# #################### SUPPORT
@app.route("/support")
def support():
url="https://daap.bannerrepeater.org/w/index.php?title=Support&action=render"
# Make a GET request to fetch the raw HTML content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
# print(soup.prettify()) # print the parsed data of html
text=soup.find("html")
text=Markup(text)
return render_template('support.html', text=text)
######################### TUTORIAL
@app.route("/tutorials")
def tutorials():
url="https://daap.bannerrepeater.org/w/index.php?title=Tutorials&action=render"
# Make a GET request to fetch the raw HTML content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
# print(soup.prettify()) # print the parsed data of html
text=soup.find("html")
text=Markup(text)
return render_template('tutorials.html', text=text)
######################### TUTORIAL 1
@app.route("/tutorial_1")
def tutorial_1():
url="https://daap.bannerrepeater.org/w/index.php?title=Tutorial_1&action=render"
# Make a GET request to fetch the raw HTML content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
# print(soup.prettify()) # print the parsed data of html
text=soup.find("html")
text=Markup(text)
return render_template('tutorials.html', text=text)
######################### TUTORIAL 2
@app.route("/tutorial_2")
def tutorial_2():
url="https://daap.bannerrepeater.org/w/index.php?title=Tutorial_2&action=render"
# Make a GET request to fetch the raw HTML content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
# print(soup.prettify()) # print the parsed data of html
text=soup.find("html")
text=Markup(text)
return render_template('tutorials.html', text=text)
######################### TUTORIAL 3
@app.route("/tutorial_3")
def tutorial_3():
url="https://daap.bannerrepeater.org/w/index.php?title=Tutorial_3&action=render"
# Make a GET request to fetch the raw HTML content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
# print(soup.prettify()) # print the parsed data of html
text=soup.find("html")
text=Markup(text)
return render_template('tutorials.html', text=text)
######################### TUTORIAL 4
@app.route("/tutorial_4")
def tutorial_4():
url="https://daap.bannerrepeater.org/w/index.php?title=Tutorial_4&action=render"
# Make a GET request to fetch the raw HTML content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
# print(soup.prettify()) # print the parsed data of html
text=soup.find("html")
text=Markup(text)
return render_template('tutorials.html', text=text)
######################### TUTORIAL 5
@app.route("/tutorial_5")
def tutorial_5():
url="https://daap.bannerrepeater.org/w/index.php?title=Tutorial_5&action=render"
# Make a GET request to fetch the raw HTML content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
# print(soup.prettify()) # print the parsed data of html
text=soup.find("html")
text=Markup(text)
return render_template('tutorials.html', text=text)
######################### TUTORIAL 6
@app.route("/tutorial_6")
def tutorial_6():
url="https://daap.bannerrepeater.org/w/index.php?title=Tutorial_6&action=render"
# Make a GET request to fetch the raw HTML content
html_content = requests.get(url).text
# Parse the html content
soup = BeautifulSoup(html_content, "lxml")
# print(soup.prettify()) # print the parsed data of html
text=soup.find("html")
text=Markup(text)
return render_template('tutorials.html', text=text)
######################### LOGIN
#Goes to wikibase page
# ALL NAME
# https://daap.bannerrepeater.org/w/api.php?action=query&meta=siteinfo&siprop=namespaces|namespacealiases
# replace or insert tags
# https://stackoverflow.com/questions/2073541/search-and-replace-in-html-with-beautifulsoup