Zache added a comment.

  @matej_suchanek Is the 
https://commons.wikimedia.org/wiki/Commons:SPARQL_query_service/API_endpoint 
outdated as pywikibot login seems to be enough?
  
  Ie. this works:
  
    import pywikibot
    import json
    from pywikibot.data import sparql
    
    # Login to pywikibot    
    site = pywikibot.Site('commons', 'commons')
    site.login()
    
    # Define the SPARQL query
    query = """
            
    SELECT ?item ?described_url WHERE {
      ?item wdt:P7482 wd:Q74228490 .       # P7482 (source of file) = Q74228490 
(file available on the internet)
      ?item p:P7482 ?statement .            
      ?statement pq:P973 ?described_url.
    } LIMIT 5
    """
                    
    # Set up the SPARQL endpoint and entity URL
    # Note: https://commons-query.wikimedia.org requires user to be logged in
                            
    entity_url = 'https://commons.wikimedia.org/entity/'
    endpoint = 'https://commons-query.wikimedia.org/sparql'
                            
    # Create a SparqlQuery object
    query_object = sparql.SparqlQuery(endpoint= endpoint, entity_url= 
entity_url)
    
    # Execute the SPARQL query and retrieve the data
    data = query_object.select(query, full_data=True)
    
    # Convert SPARQL result mediainfo uri to Pywikibot.Page() object
    for row in data:
        page_id=int(row['item'].getID().replace('M',''))
        pages = list(site.load_pages_from_pageids([page_id]))
        if len(pages) == 1:
            page=pages[0]
            print(page)

TASK DETAIL
  https://phabricator.wikimedia.org/T326762

EMAIL PREFERENCES
  https://phabricator.wikimedia.org/settings/panel/emailpreferences/

To: Zache
Cc: Zache, Aklapper, matej_suchanek, pywikibot-bugs-list, PotsdamLamb, 
Jyoo1011, JohnsonLee01, SHEKH, Dijkstra, Khutuck, Zkhalido, Viztor, Wenyi, 
Tbscho, MayS, Mdupont, JJMC89, Dvorapa, Altostratus, Avicennasis, mys_721tx, 
Xqt, jayvdb, Ricordisamoa, Masti, Alchimista
_______________________________________________
pywikibot-bugs mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to