From d928c46c1d654ec117b8cb9a5317009515d87524 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Wed, 9 Oct 2019 14:28:08 +0100 Subject: [PATCH] Support item variable not called item. --- depicts/wdqs.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/depicts/wdqs.py b/depicts/wdqs.py index 224982d..268f94e 100644 --- a/depicts/wdqs.py +++ b/depicts/wdqs.py @@ -11,8 +11,8 @@ query_url = 'https://query.wikidata.org/bigdata/namespace/wdq/sparql' url_start = 'http://www.wikidata.org/entity/Q' commons_start = 'http://commons.wikimedia.org/wiki/Special:FilePath/' -def row_id(row): - return int(utils.drop_start(row['item']['value'], url_start)) +def row_id(row, field='item'): + return int(utils.drop_start(row[field]['value'], url_start)) def get_row_value(row, field): return row[field]['value'] if field in row else None @@ -27,6 +27,8 @@ def commons_uri_to_filename(uri): def run_query(query): params = {'query': query, 'format': 'json'} r = requests.post(query_url, data=params, stream=True) + if r.status_code != 200: + print(r.text) assert r.status_code == 200 return r