import requests


def getSTCNBooks(ENDPOINT: str = "http://data.bibliotheken.nl/sparql"):
    """
    Get all books (Manifestations) from the STCN collection that have 
    "Rijksmuseum" as holding archive.

    Args:
        ENDPOINT (str, optional): SPARQL endpoint
    """

    q = """
    PREFIX rdf: <http://www.w3.org/1999/02/22-rdf-syntax-ns#>
    PREFIX rdfs: <http://www.w3.org/2000/01/rdf-schema#>
    PREFIX schema: <http://schema.org/>

    SELECT DISTINCT ?book ?title WHERE {
    ?book a schema:Book ;
            schema:name ?title .
    
    ?item a schema:IndividualProduct ;
            schema:exampleOfWork ?book ;
            # schema:itemLocation ?shelfmark ;
            schema:holdingArchive ?archive .
    
    FILTER(CONTAINS(?archive, "Rijksmuseum"))
    }
    """

    headers = {"Accept": "application/sparql-results+json"}
    params = {"query": q}
    r = requests.get(ENDPOINT, headers=headers, params=params)
    data = r.json()

    books = []
    for r in data["results"]["bindings"]:
        record = dict()
        for k, v in r.items():
            record[k] = v["value"]
        books.append(record)

    return books