jenkins-bot has submitted this change. ( https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1092883?usp=email )
Change subject: [IMPR] decrease nested flow statements in create_isbn_edition.py ...................................................................... [IMPR] decrease nested flow statements in create_isbn_edition.py Change-Id: I6cae4dd409b513a8b6e22942ac5259ed55ed1bee --- M scripts/create_isbn_edition.py 1 file changed, 24 insertions(+), 23 deletions(-) Approvals: jenkins-bot: Verified Xqt: Looks good to me, approved diff --git a/scripts/create_isbn_edition.py b/scripts/create_isbn_edition.py index 14d0d3c..d803761 100755 --- a/scripts/create_isbn_edition.py +++ b/scripts/create_isbn_edition.py @@ -782,8 +782,7 @@ :return: Set of items """ pywikibot.debug(f'Search label: {item_name.encode("utf-8")}') - item_list = set() # Empty set - # TODO: try to us search_entities instead? + # TODO: try to use search_entities instead? params = { 'action': 'wbsearchentities', 'format': 'json', @@ -799,32 +798,34 @@ result = request.submit() pywikibot.debug(result) - if 'search' in result: - # Ignore accents and case - item_name_canon = unidecode(item_name).casefold() + if 'search' not in result: + return set() - # Loop though items - for res in result['search']: - item = get_item_page(res['id']) + # Ignore accents and case + item_name_canon = unidecode(item_name).casefold() - # Matching instance - if INSTANCEPROP not in item.claims \ - or not item_is_in_list(item.claims[INSTANCEPROP], instance_id): - continue + item_list = set() + # Loop though items + for res in result['search']: + item = get_item_page(res['id']) - # Search all languages, ignore label case and accents - for lang in item.labels: - if (item_name_canon - == unidecode(item.labels[lang].casefold())): - item_list.add(item.getID()) # Label math + # Matching instance + if INSTANCEPROP not in item.claims \ + or not item_is_in_list(item.claims[INSTANCEPROP], instance_id): + continue + + # Search all languages, ignore label case and accents + for lang in item.labels: + if item_name_canon == unidecode(item.labels[lang].casefold()): + item_list.add(item.getID()) # Label math + break + + for lang in item.aliases: + for seq in item.aliases[lang]: + if item_name_canon == unidecode(seq).casefold(): + item_list.add(item) # Alias match break - for lang in item.aliases: - for seq in item.aliases[lang]: - if item_name_canon == unidecode(seq).casefold(): - item_list.add(item) # Alias match - break - pywikibot.log(item_list) return item_list -- To view, visit https://gerrit.wikimedia.org/r/c/pywikibot/core/+/1092883?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.wikimedia.org/r/settings?usp=email Gerrit-MessageType: merged Gerrit-Project: pywikibot/core Gerrit-Branch: master Gerrit-Change-Id: I6cae4dd409b513a8b6e22942ac5259ed55ed1bee Gerrit-Change-Number: 1092883 Gerrit-PatchSet: 2 Gerrit-Owner: Xqt <i...@gno.de> Gerrit-Reviewer: Xqt <i...@gno.de> Gerrit-Reviewer: jenkins-bot
_______________________________________________ Pywikibot-commits mailing list -- pywikibot-commits@lists.wikimedia.org To unsubscribe send an email to pywikibot-commits-le...@lists.wikimedia.org