From 9688331190b7a7b95a1595cb9e7972d2e06cc4b0 Mon Sep 17 00:00:00 2001 From: Edward Betts Date: Mon, 7 Oct 2019 10:38:26 +0100 Subject: [PATCH] Add option to return wikibase entities as dict. --- depicts/mediawiki.py | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/depicts/mediawiki.py b/depicts/mediawiki.py index 72cc8b1..3887f95 100644 --- a/depicts/mediawiki.py +++ b/depicts/mediawiki.py @@ -43,6 +43,16 @@ def get_entities(ids, **params): json_data = r.json() return list(json_data['entities'].values()) +def get_entities_dict(ids, **params): + if not ids: + return [] + params = { + 'action': 'wbgetentities', + 'ids': '|'.join(ids), + **params, + } + return api_call(params).json()['entities'] + def get_entity_with_cache(qid): filename = f'cache/{qid}.json' if os.path.exists(filename):