Created
May 17, 2021 14:05
-
-
Save lubianat/69d66dd008735726bc7ff21b6c62c684 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import requests | |
import sys | |
import pandas as pd | |
url = sys.argv[1] | |
session = requests.Session() # so connections are recycled | |
resp = session.head(url, allow_redirects=True) | |
url_sparql = resp.url.replace("https://query.wikidata.org/#", "https://query.wikidata.org/sparql?query=") | |
r = requests.get(url_sparql, params = {'format':'json'}) | |
df = pd.json_normalize(r.json()["results"]["bindings"]) | |
df["qid"] = [url.split("/")[4] for url in df["work.value"]] | |
for i in df["qid"]: | |
print(i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
this assumes that there is variable being selected called "?work", by the way