Skip to content

Commit 3f381b9

Browse files
committed
Adjusted PR #98 for any non-value snaktype.
1 parent 1281bf0 commit 3f381b9

File tree

2 files changed

+15
-11
lines changed

2 files changed

+15
-11
lines changed

tests/test_basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1003,7 +1003,7 @@ def test_wikidata_no_value_snak(self):
10031003
page = wptools.wikidata(skip=SKIP_FLAG, silent=SILENT_FLAG)
10041004
page.cache = {'wikidata': wikidata_novalue_snak.cache}
10051005
page._set_data('wikidata')
1006-
self.assertEqual(len(page.data['claims']), 1)
1006+
self.assertEqual(len(page.data['claims']), 2)
10071007

10081008

10091009
class WPToolsToolTestCase(unittest.TestCase):

wptools/wikidata.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -360,21 +360,25 @@ def reduce_claims(query_claims):
360360
for ent in entities:
361361

362362
try:
363-
snak = ent.get('mainsnak').get('datavalue').get('value')
363+
snak = ent.get('mainsnak')
364+
snaktype = snak.get('snaktype')
365+
value = snak.get('datavalue').get('value')
364366
except AttributeError:
365-
continue
367+
claims[claim] = []
366368

367369
try:
368-
if snak.get('id'):
369-
val = snak.get('id')
370-
elif snak.get('text'):
371-
val = snak.get('text')
372-
elif snak.get('time'):
373-
val = snak.get('time')
370+
if snaktype != 'value':
371+
val = snaktype
372+
elif value.get('id'):
373+
val = value.get('id')
374+
elif value.get('text'):
375+
val = value.get('text')
376+
elif value.get('time'):
377+
val = value.get('time')
374378
else:
375-
val = snak
379+
val = value
376380
except AttributeError:
377-
val = snak
381+
val = value
378382

379383
if not val or not [x for x in val if x]:
380384
raise ValueError("%s %s" % (claim, ent))

0 commit comments

Comments
 (0)