# Basic script for https://nl.wikipedia.org/wiki/Wikipedia:GLAM/Koninklijke_Bibliotheek_en_Nationaal_Archief/Topstukken/Hergebruik/Voorbeelden/Smoelenboek_bijdragers_AAJH#4)_SPARQL-query_op_Wikidata_met_JSON-respons
# Also used on Github for
# https://github.com/KBNLwikimedia/Alba-Amicorum/tree/main/alba/AA-Jacob-Heyblocq/reuse/index.md and
# https://kbnlwikimedia.github.io/Alba-Amicorum/alba/AA-Jacob-Heyblocq/reuse/
# We request data about the contributors to the album amicorum from the SPARQL endpoint on Wikidata via
# https://w.wiki/soe
# SELECT DISTINCT ?contributor ?contributorLabel ?contributorDescription ?image ?commonscat ?wparticleNL WHERE {
# BIND(wd:Q72752496 as ?album)
# ?album wdt:P767 ?contributor.
# ?contributor wdt:P18 ?image.
# OPTIONAL{?contributor wdt:P373 ?commonscat.}
# OPTIONAL{?wparticleNL schema:about ?contributor.
# ?wparticleNL schema:isPartOf .}
# SERVICE wikibase:label { bd:serviceParam wikibase:language "nl". }
# }
# ORDER BY ?contributorLabel
# Or, the above query with a json response:
# https://query.wikidata.org/sparql?query=SELECT%20DISTINCT%20%3Fcontributor%20%3FcontributorLabel%20%3FcontributorDescription%20%3Fimage%20%3Fcommonscat%20%3FwparticleNL%20WHERE%20%7B%20%0A%20%20BIND(wd%3AQ72752496%20as%20%3Falbum)%0A%20%20%3Falbum%20wdt%3AP767%20%3Fcontributor.%0A%20%20%3Fcontributor%20wdt%3AP18%20%3Fimage.%0A%20%20OPTIONAL%7B%3Fcontributor%20wdt%3AP373%20%3Fcommonscat.%7D%0A%20%20OPTIONAL%7B%3FwparticleNL%20schema%3Aabout%20%3Fcontributor.%0A%20%20%20%20%20%20%20%20%20%20%20%3FwparticleNL%20schema%3AisPartOf%20%3Chttps%3A%2F%2Fnl.wikipedia.org%2F%3E.%7D%0A%20%20SERVICE%20wikibase%3Alabel%20%7B%20bd%3AserviceParam%20wikibase%3Alanguage%20%22nl%22.%20%7D%0A%7D%20%0AORDER%20BY%20%3FcontributorLabel&format=json
# We process this json into a basic image thumb gallery (facebook, Dutch:smoelenboek) in HTML, using the code below
######################################################################
import json
import requests
import hashlib
import urllib.parse
from bs4 import BeautifulSoup
HTMLtemplate ="""
Facebook of contributors to the album amicorum of Jacob Heyblocq - Demo for using a SPARQL-query on Wikidata with JSON-response