Skip to content

Instantly share code, notes, and snippets.

@salgo60
Created June 17, 2020 08:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save salgo60/b6664b2aa4b6b7d613374db2f02a5314 to your computer and use it in GitHub Desktop.
Save salgo60/b6664b2aa4b6b7d613374db2f02a5314 to your computer and use it in GitHub Desktop.
import pandas as pd
import pprint
import os
from wikidataintegrator import wdi_core, wdi_login
mediawiki_api_url = "https://swebase.wiki.opencura.com/w/api.php" # <- change to applicable wikibase
sparql_endpoint_url = "https://swebase.wiki.opencura.com//query/sparql" # <- change to applicable wikibase
if "SWEBASEUSER" in os.environ and "SWEBASEPASS" in os.environ:
WBUSER = os.environ['SWEBASEUSER']
WBPASS = os.environ['SWEBASEPASS']
else:
raise ValueError("SWEBASEUSER and SWEBASEPASS must be specified in local.py or as environment variables")
login = wdi_login.WDLogin(WBUSER, WBPASS, mediawiki_api_url=mediawiki_api_url)
print("=Look at current content in SWEBASE....")
query = """
PREFIX wdt: <https://swebase.wiki.opencura.com/prop/direct/>
SELECT DISTINCT ?s ?p ?o WHERE {
?s ?p ?o }
"""
results = wdi_core.WDItemEngine.execute_sparql_query(query, endpoint=sparql_endpoint_url)
for result in results["results"]["bindings"]:
#pprint.pprint(result)
pprint.pprint(result["s"]["value"])
@salgo60
Copy link
Author

salgo60 commented Jun 17, 2020

Verkar funka output

/usr/local/bin/python3.8 /Users/magnus/Library/Preferences/PyCharmCE2019.2/scratches/scratch_86.py
https://swebase.wiki.opencura.com/w/api.php
Successfully logged in as Salgo60
=Look at current content in SWEBASE....
'http://swebase.wiki.opencura.com/entity/Q1'
'http://swebase.wiki.opencura.com/entity/Q1'
'http://swebase.wiki.opencura.com/entity/Q1'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment