Skip to content

Commit 09bdfb2

Browse files
jenkins-botGerrit Code Review
authored andcommitted
Merge "[IMPR] use search_entities method in get_item_list function"
2 parents 644583e + c8b185f commit 09bdfb2

File tree

1 file changed

+2
-22
lines changed

1 file changed

+2
-22
lines changed

scripts/create_isbn_edition.py

Lines changed: 2 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -781,32 +781,12 @@ def get_item_list(item_name: str,
781781
:param instance_id: Instance ID
782782
:return: Set of items
783783
"""
784-
pywikibot.debug(f'Search label: {item_name.encode("utf-8")}')
785-
# TODO: try to use search_entities instead?
786-
params = {
787-
'action': 'wbsearchentities',
788-
'format': 'json',
789-
'type': 'item',
790-
# All languages are searched, but labels are in native language
791-
'strictlanguage': False,
792-
'language': mainlang,
793-
'uselang': mainlang, # (primary) Search language
794-
'search': item_name, # Get item list from label
795-
'limit': 20, # Should be reasonable value
796-
}
797-
request = api.Request(site=repo, parameters=params)
798-
result = request.submit()
799-
pywikibot.debug(result)
800-
801-
if 'search' not in result:
802-
return set()
803-
804784
# Ignore accents and case
805785
item_name_canon = unidecode(item_name).casefold()
806786

807787
item_list = set()
808-
# Loop though items
809-
for res in result['search']:
788+
# Loop though items, total should be reasonable value
789+
for res in repo.search_entities(item_name, mainlang, total=20):
810790
item = get_item_page(res['id'])
811791

812792
# Matching instance

0 commit comments

Comments
 (0)