Last active
March 6, 2021 09:22
-
-
Save dridk/07770677340f1dd68960819a2657c50b to your computer and use it in GitHub Desktop.
How to download, from wikidata, all picture with a penis
This file contains hidden or 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
from qwikidata.sparql import return_sparql_query_results | |
import urllib.request | |
from urllib.parse import urlparse, unquote | |
import os | |
q = """ | |
SELECT ?item ?object ?image | |
WHERE | |
{ | |
?item wdt:P31/wdt:P279* wd:Q4502142 . | |
?item wdt:P180 ?object . | |
?object wdt:P279* wd:Q58 . | |
?item wdt:P18 ?image . | |
} | |
""" | |
items = return_sparql_query_results(q) | |
for item in items["results"]["bindings"]: | |
img_url = item["image"]["value"] | |
filename = os.path.basename(urlparse(unquote(img_url)).path) | |
print("Download", filename) | |
urllib.request.urlretrieve(img_url, filename) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment