Skip to content

Commit

Permalink
Merge "[IMPR] use search_entities method in get_item_list function"
Browse files Browse the repository at this point in the history
  • Loading branch information
jenkins-bot authored and Gerrit Code Review committed Nov 27, 2024
2 parents 644583e + c8b185f commit 09bdfb2
Showing 1 changed file with 2 additions and 22 deletions.
24 changes: 2 additions & 22 deletions scripts/create_isbn_edition.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 09bdfb2

Please sign in to comment.