From c8b185f7fed7640fd46021d557928bf8d265c4a7 Mon Sep 17 00:00:00 2001 From: xqt Date: Wed, 20 Nov 2024 16:58:20 +0100 Subject: [PATCH] [IMPR] use search_entities method in get_item_list function Change-Id: I7d033572a0595b73bd8f0f5892a939a2c13e46e9 --- scripts/create_isbn_edition.py | 24 ++---------------------- 1 file changed, 2 insertions(+), 22 deletions(-) diff --git a/scripts/create_isbn_edition.py b/scripts/create_isbn_edition.py index d803761330..c566fbc783 100755 --- a/scripts/create_isbn_edition.py +++ b/scripts/create_isbn_edition.py @@ -781,32 +781,12 @@ def get_item_list(item_name: str, :param instance_id: Instance ID :return: Set of items """ - pywikibot.debug(f'Search label: {item_name.encode("utf-8")}') - # TODO: try to use search_entities instead? - params = { - 'action': 'wbsearchentities', - 'format': 'json', - 'type': 'item', - # All languages are searched, but labels are in native language - 'strictlanguage': False, - 'language': mainlang, - 'uselang': mainlang, # (primary) Search language - 'search': item_name, # Get item list from label - 'limit': 20, # Should be reasonable value - } - request = api.Request(site=repo, parameters=params) - result = request.submit() - pywikibot.debug(result) - - if 'search' not in result: - return set() - # Ignore accents and case item_name_canon = unidecode(item_name).casefold() item_list = set() - # Loop though items - for res in result['search']: + # Loop though items, total should be reasonable value + for res in repo.search_entities(item_name, mainlang, total=20): item = get_item_page(res['id']) # Matching instance