From 0890a7514a5ba7f72b10ff3c59fec29f625e7c99 Mon Sep 17 00:00:00 2001 From: jules Date: Mon, 14 Dec 2020 23:06:34 +0100 Subject: [PATCH] template item for person org and collective --- daapinterface.py | 392 +++++++++++++++++++---- templates/artistsindex.html | 4 +- templates/artwork.html | 4 +- templates/item.html | 563 +++++++++++++++++++++++++++++++++ templates/publishersindex.html | 4 +- templates/searchtools.html | 9 +- templates/tutorials.html | 2 - 7 files changed, 912 insertions(+), 66 deletions(-) create mode 100644 templates/item.html diff --git a/daapinterface.py b/daapinterface.py index 080c5ce..a2400c1 100644 --- a/daapinterface.py +++ b/daapinterface.py @@ -221,7 +221,7 @@ def zinesindex(): ''') sparql.setReturnFormat(JSON) results = sparql.query().convert() - print(results) + # print(results) return render_template('zinesindex.html', results=results) @@ -264,7 +264,7 @@ def artwork(): sparql.setReturnFormat(JSON) artworkimages = sparql.query().convert() - print(artworkimages) + # print(artworkimages) # Links and downloads sparql.setQuery(''' @@ -545,51 +545,156 @@ def artwork(): ######################### CONTRIBUTOR : PERSON - ORGANISATION -@app.route("/contributor", methods=['GET']) -def contributor(): - contributor_id = request.args.get('id') +@app.route("/item", methods=['GET']) +def item(): + item_id = request.args.get('id') # Intro sparql.setQuery(''' SELECT ?item ?itemLabel ?itemDescription ?itemtypeLabel { - VALUES ?item {wd:'''+contributor_id+'''} + VALUES ?item {wd:'''+item_id+'''} ?item wdt:P1 ?itemtype. SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } ''') sparql.setReturnFormat(JSON) - contributorintro = sparql.query().convert() - # print("person intro") - # print(contributorintro) - # print("==========") + itemintro = sparql.query().convert() + # image sparql.setQuery(''' SELECT ?image ?depictsLabel ?licenseLabel WHERE { - VALUES ?item {wd:'''+contributor_id+'''} - ?item wdt:P30 ?image. - OPTIONAL { ?work p:P30 ?statement2. - ?statement2 ps:P30 ?image; + 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) - contributorimage = sparql.query().convert() - # print(contributorimage) - # print("==========") + 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() -# biography +# PERSON biography sparql.setQuery(''' SELECT ?accessURLbioPage ?authorBioPageLabel ?dateBioPage ?sourceBioPageLabel WHERE { - VALUES ?item {wd:'''+contributor_id+'''} + VALUES ?item {wd:'''+item_id+'''} ?item wdt:P67 ?bioPage. OPTIONAL { ?bioPage wdt:P4 ?accessURLbioPage. } OPTIONAL { ?bioPage wdt:P9 ?authorBioPage. } @@ -599,17 +704,57 @@ def contributor(): } ''') sparql.setReturnFormat(JSON) - contributorbiography = sparql.query().convert() + personbiography = sparql.query().convert() - for x in contributorbiography['results']['bindings']: + 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 - contributorbiocontenturl = "https://daap.bannerrepeater.org/w/index.php?title=Biography:Q"+desc_id+"&action=render" + 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="

Information not available

" + 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(contributorbiocontenturl).text + html_content = requests.get(itemdesccontenturl).text # # Parse the html content soup = BeautifulSoup(html_content, "lxml") # # print(soup.prettify()) # print the parsed data of html @@ -632,7 +777,7 @@ def contributor(): SELECT ?Works ?WorksLabel (SAMPLE(?dateWorks) AS ?dateWorks) WHERE { - VALUES ?item {wd:'''+contributor_id+'''} + VALUES ?item {wd:'''+item_id+'''} ?Works wdt:P1 wd:Q1; wdt:P9 ?item; wdt:P13 ?dateWorks. @@ -646,10 +791,10 @@ def contributor(): SELECT ?Works ?WorksLabel (SAMPLE(?image) AS ?image) WHERE { - VALUES ?item {wd:'''+contributor_id+'''} + VALUES ?item {wd:'''+item_id+'''} ?Works wdt:P1 wd:Q1; wdt:P9 ?item. - OPTIONAL {?Works wdt:P30 ?image.} + OPTIONAL {?Works wdt:P90 ?image.} SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } GROUP BY ?Works ?WorksLabel @@ -658,9 +803,8 @@ def contributor(): } ''') sparql.setReturnFormat(JSON) - contributor_creatorof = sparql.query().convert() - # print(contributor_creatorof) - # print("==========") + item_creatorof = sparql.query().convert() + # publisher of sparql.setQuery(''' @@ -670,7 +814,7 @@ def contributor(): SELECT ?Works ?WorksLabel (SAMPLE(?dateWorks) AS ?dateWorks) WHERE { - VALUES ?item {wd:'''+contributor_id+'''} + VALUES ?item {wd:'''+item_id+'''} ?Works wdt:P1 wd:Q1; wdt:P10 ?item; wdt:P13 ?dateWorks. @@ -684,10 +828,10 @@ def contributor(): SELECT ?Works ?WorksLabel (SAMPLE(?image) AS ?image) WHERE { - VALUES ?item {wd:'''+contributor_id+'''} + VALUES ?item {wd:'''+item_id+'''} ?Works wdt:P1 wd:Q1; wdt:P10 ?item. - OPTIONAL {?Works wdt:P30 ?image.} + OPTIONAL {?Works wdt:P90 ?image.} SERVICE wikibase:label { bd:serviceParam wikibase:language "en". } } GROUP BY ?Works ?WorksLabel @@ -696,16 +840,47 @@ def contributor(): } ''') sparql.setReturnFormat(JSON) - contributor_publisherof = sparql.query().convert() - # print(contributor_publisherof) - # print("============") + 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() - contributor_url = "" - contributor_name = "the name" - contributor_description = "short bio" - return render_template("contributor.html", contributor_id=contributor_id, contributor_creatorof=contributor_creatorof, contributor_publisherof=contributor_publisherof, contributorintro=contributorintro, contributorimage=contributorimage, contributorbiography=contributorbiography) + + 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 @@ -719,10 +894,6 @@ def organisation(): # PAGES FROM WIKI ######################### -######################### SEARCH TOOLS -@app.route("/searchtools") -def searchtools(): - return render_template('searchtools.html') ######################### ABOUT @app.route("/about") @@ -750,20 +921,6 @@ def about(): text=Markup(text) return render_template('about.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') - ######################### UPLOAD @app.route("/upload") @@ -814,6 +971,127 @@ def codeofconduct(): 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) + +######################### 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 diff --git a/templates/artistsindex.html b/templates/artistsindex.html index b778a6d..ceeb399 100644 --- a/templates/artistsindex.html +++ b/templates/artistsindex.html @@ -15,8 +15,8 @@ {% for x in results['results']['bindings']%} - {{ x['creators']['value'] | replace('http://daap.bannerrepeater.org/entity/', '') }} - {{ x["creatorsLabel"]['value'] }} + {{ x['creators']['value'] | replace('http://daap.bannerrepeater.org/entity/', '') }} + {{ x["creatorsLabel"]['value'] }} {% if "creatorsAltLabel" in x %} {{ x["creatorsAltLabel"]["value"] }} diff --git a/templates/artwork.html b/templates/artwork.html index 3cfc778..1f5d4c6 100644 --- a/templates/artwork.html +++ b/templates/artwork.html @@ -197,7 +197,7 @@ {% for x in artworkcontributors['results']['bindings'] %}