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.
266 lines
9.4 KiB
266 lines
9.4 KiB
4 years ago
|
# 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
|
||
|
|
||
|
# # # # # # # # # # # # # # # # # # # # # # # #
|
||
|
# GETTING STARTED
|
||
|
# # # # # # # # # # # # # # # # # # # # # # # #
|
||
|
app = Flask(__name__, static_url_path='', static_folder="static", template_folder="templates")
|
||
|
app.jinja_env.add_extension('jinja2.ext.loopcontrols')
|
||
|
|
||
|
|
||
|
# # # # # # # # # # # # # # # # # # # # # # # #
|
||
|
# GETTING WIKIBASE DATA
|
||
|
# # # # # # # # # # # # # # # # # # # # # # # #
|
||
|
|
||
|
sparql = SPARQLWrapper("https://query.daap.bannerrepeater.org/proxy/wdqs/bigdata/namespace/wdq/sparql")
|
||
|
sparql2 = SPARQLWrapper("https://query.daap.bannerrepeater.org/proxy/wdqs/bigdata/namespace/wdq/sparql")
|
||
|
sparql3 = SPARQLWrapper("https://query.daap.bannerrepeater.org/proxy/wdqs/bigdata/namespace/wdq/sparql")
|
||
|
|
||
|
|
||
|
# # # # # # # # # # # # # # # # # # # # # # # #
|
||
|
# PAGES
|
||
|
# # # # # # # # # # # # # # # # # # # # # # # #
|
||
|
@app.route("/")
|
||
|
def home():
|
||
|
# this doesn't show any results yet because I just added the data and I guess the query builder needs to be reloaded again, but the query code should work correctly.
|
||
|
sparql.setQuery('''
|
||
|
SELECT ?work ?workLabel ?image ?date ?dateadded
|
||
|
WHERE {
|
||
|
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
|
||
|
?work wdt:P1 wd:Q1;
|
||
|
wdt:P87 ?dateadded.
|
||
|
OPTIONAL { ?work wdt:P30 ?image. }
|
||
|
OPTIONAL { ?work wdt:P13 ?date. }
|
||
|
FILTER(?work != wd:Q57)
|
||
|
}
|
||
|
ORDER BY (?dateadded)
|
||
|
LIMIT 24
|
||
|
''')
|
||
|
sparql.setReturnFormat(JSON)
|
||
|
results = sparql.query().convert()
|
||
|
return render_template('home.html')
|
||
|
|
||
|
|
||
|
@app.route("/browsethearchive")
|
||
|
def browsethearchive():
|
||
|
sparql.setQuery('''
|
||
|
SELECT ?work ?workLabel ?image ?date
|
||
|
WHERE {
|
||
|
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
|
||
|
?work wdt:P1 wd:Q1.
|
||
|
OPTIONAL { ?work wdt:P30 ?image. }
|
||
|
OPTIONAL { ?work wdt:P13 ?date. }
|
||
|
FILTER(?work != wd:Q57)
|
||
|
}
|
||
|
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')
|
||
|
|
||
|
|
||
|
######################### ARTIST INDEX
|
||
|
@app.route("/artistsindex")
|
||
|
def artistsindex():
|
||
|
sparql.setQuery('''
|
||
|
SELECT ?creators ?creatorsLabel ?creatorsAltLabel ?creatorsDescription
|
||
|
WHERE {
|
||
|
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
|
||
|
?work wdt:P1 wd:Q1.
|
||
|
?work wdt:P9 ?creators.
|
||
|
FILTER (?creators != wd:Q82)
|
||
|
}
|
||
|
''')
|
||
|
sparql.setReturnFormat(JSON)
|
||
|
results = sparql.query().convert()
|
||
|
return render_template('artistsindex.html', results=results)
|
||
|
|
||
|
######################### ARTWORK
|
||
|
@app.route("/artwork", methods=['GET'])
|
||
|
def artwork():
|
||
|
artwork_id = request.args.get('id')
|
||
|
|
||
|
# sparql.setQuery('''
|
||
|
# SELECT ?workLabel ?workDescription
|
||
|
# ?creators ?creatorsLabel ?creatorRoles ?creatorRolesLabel
|
||
|
# ?publishers ?publishersLabel ?publisherRoles ?publisherRolesLabel
|
||
|
# ?date ?dateType ?dateTypeLabel ?dateSource
|
||
|
# ?image ?depicts ?depictsLabel ?annotation ?license ?licenseLabel
|
||
|
# ?descriptionPage ?accessURLdescriptionPage ?authordescriptionPage ?authordescriptionPageLabel ?datedescriptionPage ?sourcedescriptionPage
|
||
|
# ?exhibitionHisPage ?accessURLexhibitionHisPage ?authorexhibitionHisPage ?authorexhibitionHisPageLabel ?dateexhibitionHisPage ?sourceexhibitionHisPage
|
||
|
# ?digitalFacsimile ?digitalFacsimileExternal
|
||
|
# ?digitalArtefact ?format ?formatLabel
|
||
|
# ?distributorLinks
|
||
|
# ?copiesCollections ?collections ?collectionsLabel ?imageCollections
|
||
|
# ?relatedWorks ?relatedWorksLabel ?daterelatedWorks
|
||
|
|
||
|
# WHERE {
|
||
|
# SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
|
||
|
# VALUES ?work {wd:'''+artwork_id+'''}
|
||
|
# OPTIONAL { ?work wdt:P9 ?creators. }
|
||
|
# OPTIONAL { ?work p:P9 ?statement0.
|
||
|
# ?statement0 ps:P9 ?creators;
|
||
|
# pq:P49 ?creatorRoles. }
|
||
|
|
||
|
# OPTIONAL { ?work wdt:P13 ?date. }
|
||
|
# OPTIONAL { ?work p:P13 ?statement1.
|
||
|
# ?statement1 ps:P13 ?date;
|
||
|
# pq:P51 ?dateType. }
|
||
|
# OPTIONAL { ?work p:P13 ?statement1.
|
||
|
# ?statement1 ps:P13 ?date;
|
||
|
# pq:P50 ?dateSource. }
|
||
|
|
||
|
# OPTIONAL { ?work wdt:P10 ?publishers. }
|
||
|
# OPTIONAL { ?work p:P10 ?statement2.
|
||
|
# ?statement2 ps:P10 ?publishers;
|
||
|
# pq:P49 ?publisherRoles. }
|
||
|
|
||
|
# OPTIONAL { ?work wdt:P30 ?image. }
|
||
|
# OPTIONAL { ?work p:P30 ?statement3.
|
||
|
# ?statement3 ps:P30 ?image;
|
||
|
# pq:P54 ?depicts.}
|
||
|
# OPTIONAL { ?work p:P30 ?statement3.
|
||
|
# ?statement3 ps:P30 ?image;
|
||
|
# pq:P55 ?annotation.}
|
||
|
# OPTIONAL { ?work p:P30 ?statement3.
|
||
|
# ?statement3 ps:P30 ?image;
|
||
|
# pq:P56 ?license.}
|
||
|
|
||
|
# OPTIONAL { ?work wdt:P65 ?descriptionPage. }
|
||
|
# OPTIONAL { ?description wdt:P4 ?accessURLdescriptionPage. }
|
||
|
# OPTIONAL { ?description wdt:P9 ?authordescriptionPage. }
|
||
|
# OPTIONAL { ?description wdt:P13 ?datedescriptionPage. }
|
||
|
# OPTIONAL { ?description wdt:P50 ?sourcedescriptionPage. }
|
||
|
|
||
|
# OPTIONAL { ?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 { ?work wdt:P32 ?digitalFacsimile. }
|
||
|
# OPTIONAL { ?work wdt:P34 ?digitalFacsimileExternal. }
|
||
|
|
||
|
# OPTIONAL { ?work wdt:P35 ?digitalArtefact. }
|
||
|
# OPTIONAL { ?work p:P35 ?statement4.
|
||
|
# ?statement4 ps:P35 ?digitalArtefact;
|
||
|
# pq:P16 ?format.}
|
||
|
|
||
|
# OPTIONAL { ?work wdt:P37 ?distributorLinks. }
|
||
|
|
||
|
# OPTIONAL { ?work wdt:P43 ?copiesCollections. }
|
||
|
# OPTIONAL { ?copiesCollections wdt:P47 ?collections. }
|
||
|
# OPTIONAL { ?copiesCollections wdt:P30 ?imageCollections. }
|
||
|
|
||
|
# OPTIONAL { ?work wdt:P44 ?relatedWorks.}
|
||
|
# OPTIONAL { ?relatedWorks wdt:P13 ?daterelatedWorks. }
|
||
|
# }
|
||
|
|
||
|
# ''')
|
||
|
# sparql.setReturnFormat(JSON)
|
||
|
# artwork = sparql.query().convert()
|
||
|
# print(artwork)
|
||
|
|
||
|
artwork_url = "https://daap.bannerrepeater.org/wiki/Item:Q92"
|
||
|
artwork_title = "the human printer"
|
||
|
artwork_description = "short description"
|
||
|
return render_template('artwork.html', artwork_title=artwork_title, artwork_description=artwork_description)
|
||
|
|
||
|
######################### PERSON
|
||
|
@app.route("/person", methods=['GET'])
|
||
|
def person():
|
||
|
person_id = request.args.get('id')
|
||
|
sparql.setQuery('''
|
||
|
SELECT ?work ?workLabel ?image ?date
|
||
|
WHERE {
|
||
|
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
|
||
|
?work wdt:P1 wd:Q1.
|
||
|
?work wdt:P9 wd:'''+person_id+'''.
|
||
|
OPTIONAL { ?work wdt:P30 ?image. }
|
||
|
OPTIONAL { ?work wdt:P13 ?date. }
|
||
|
FILTER(?work != wd:Q57)
|
||
|
}
|
||
|
ORDER BY (?workLabel)
|
||
|
''')
|
||
|
sparql.setReturnFormat(JSON)
|
||
|
person_creatorof = sparql.query().convert()
|
||
|
|
||
|
sparql2.setQuery('''
|
||
|
SELECT ?work ?workLabel ?image ?date
|
||
|
WHERE {
|
||
|
SERVICE wikibase:label { bd:serviceParam wikibase:language "[AUTO_LANGUAGE],en". }
|
||
|
?work wdt:P1 wd:Q1.
|
||
|
?work wdt:P10 wd:'''+person_id+'''.
|
||
|
OPTIONAL { ?work wdt:P30 ?image. }
|
||
|
OPTIONAL { ?work wdt:P13 ?date. }
|
||
|
FILTER(?work != wd:Q57)
|
||
|
}
|
||
|
ORDER BY (?workLabel)
|
||
|
''')
|
||
|
sparql2.setReturnFormat(JSON)
|
||
|
person_publisherof = sparql2.query().convert()
|
||
|
|
||
|
person_url = ""
|
||
|
person_name = "the name"
|
||
|
person_description = "short bio"
|
||
|
return render_template("person.html", person_id=person_id, person_creatorof=person_creatorof, person_publisherof=person_publisherof)
|
||
|
|
||
|
|
||
|
|
||
|
#########################
|
||
|
# PAGES FROM WIKI
|
||
|
#########################
|
||
|
|
||
|
######################### SEARCH TOOLS
|
||
|
@app.route("/searchtools")
|
||
|
def searchtools():
|
||
|
return render_template('searchtools.html')
|
||
|
|
||
|
######################### ABOUT
|
||
|
@app.route("/about")
|
||
|
def about():
|
||
|
return render_template('about.html')
|
||
|
|
||
|
######################### TUTORIAL
|
||
|
@app.route("/tutorials")
|
||
|
def tutorials():
|
||
|
return render_template('tutorials.html')
|
||
|
|
||
|
|
||
|
######################### UPLOAD
|
||
|
@app.route("/upload")
|
||
|
def upload():
|
||
|
return render_template('upload.html')
|
||
|
|
||
|
|
||
|
######################### LOGIN
|
||
|
#Goes to wikibase page
|
||
|
|
||
|
|
||
|
|
||
|
|
||
|
# ALL NAME SPACES
|
||
|
# https://daap.bannerrepeater.org/w/api.php?action=query&meta=siteinfo&siprop=namespaces|namespacealiases
|
||
|
|