Skip to content

Commit

Permalink
Adjusted PR #98 for any non-value snaktype.
Browse files Browse the repository at this point in the history
  • Loading branch information
siznax committed Jan 9, 2018
1 parent 1281bf0 commit 3f381b9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 11 deletions.
2 changes: 1 addition & 1 deletion tests/test_basic.py
Expand Up @@ -1003,7 +1003,7 @@ def test_wikidata_no_value_snak(self):
page = wptools.wikidata(skip=SKIP_FLAG, silent=SILENT_FLAG)
page.cache = {'wikidata': wikidata_novalue_snak.cache}
page._set_data('wikidata')
self.assertEqual(len(page.data['claims']), 1)
self.assertEqual(len(page.data['claims']), 2)


class WPToolsToolTestCase(unittest.TestCase):
Expand Down
24 changes: 14 additions & 10 deletions wptools/wikidata.py
Expand Up @@ -360,21 +360,25 @@ def reduce_claims(query_claims):
for ent in entities:

try:
snak = ent.get('mainsnak').get('datavalue').get('value')
snak = ent.get('mainsnak')
snaktype = snak.get('snaktype')
value = snak.get('datavalue').get('value')
except AttributeError:
continue
claims[claim] = []

try:
if snak.get('id'):
val = snak.get('id')
elif snak.get('text'):
val = snak.get('text')
elif snak.get('time'):
val = snak.get('time')
if snaktype != 'value':
val = snaktype
elif value.get('id'):
val = value.get('id')
elif value.get('text'):
val = value.get('text')
elif value.get('time'):
val = value.get('time')
else:
val = snak
val = value
except AttributeError:
val = snak
val = value

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

0 comments on commit 3f381b9

Please sign in to comment.