import requests
# Global variables
= 'https://wikibase.wbworkshop.tibwiki.io'
endpoint_url = '/w/api.php'
resource_url
= input("What's the Q number (including the 'Q')? ")
entity print('Check out ' + endpoint_url + '/wiki/' + entity + ' to see the GUI.')
= '/w/api.php?action=wbgetclaims&format=json&entity='+entity
resourceUrl = endpoint_url + resourceUrl
uri = requests.get(uri)
r = r.json()
data = data['claims']
claims print('subject: ', entity)
print()
for property, values in claims.items():
print('property: ', property)
for value in values:
try:
# print Q ID if the value is an item
print('item value: ', value['mainsnak']['datavalue']['value']['id'])
except:
try:
# print the string value if the value is a literal
print('literal value: ', value['mainsnak']['datavalue']['value'])
except:
# print the whole snak if the value is something else
print('other value: ', value['mainsnak'])
print()
9 Linked open data API testing
9.1 Linked open data API testing
This notebook experiments with querying linked open data in a Jupyter Notebook rendered through Quarto.
The Python code below queries the NFDI4Culture Wikibase at https://wikibase.wbworkshop.tibwiki.io/wiki/Main_Page and returns data based on the ID inputted by the user.
This executes in Jupyter Notebook which is able to run the Python code and provides a static output when saved in the Notebook. It cannot be executed dynamically in Quarto since the Quarto front-end does not support stdin input requests.
To reset the output, run ‘Kernel > Restart kernel and clear all outputs’.