[scripts] fix a bug in run_chooser when no search results are found

This commit is contained in:
Dmytro Meleshko 2021-04-12 00:53:51 +03:00
parent 661aa1785c
commit 855538c921
2 changed files with 25 additions and 23 deletions

View file

@ -61,26 +61,27 @@ def emote_downloader_and_iterator():
chosen_index = common_script_utils.run_chooser( chosen_index = common_script_utils.run_chooser(
emote_downloader_and_iterator(), prompt="emote", async_read=True emote_downloader_and_iterator(), prompt="emote", async_read=True
) )
chosen_emote = emotes[chosen_index] if chosen_index >= 0:
chosen_emote = emotes[chosen_index]
emote_url = urllib.parse.urlparse(chosen_emote["url"]) emote_url = urllib.parse.urlparse(chosen_emote["url"])
emote_url_query = urllib.parse.parse_qs(emote_url.query) emote_url_query = urllib.parse.parse_qs(emote_url.query)
if config.getboolean("default", "add_emote_name_to_url", fallback=False): if config.getboolean("default", "add_emote_name_to_url", fallback=False):
emote_url_query["name"] = [chosen_emote["name"]] emote_url_query["name"] = [chosen_emote["name"]]
default_emote_image_size = config.getint( default_emote_image_size = config.getint(
"default", "default_emote_image_size", fallback=None "default", "default_emote_image_size", fallback=None
) )
if default_emote_image_size is not None: if default_emote_image_size is not None:
emote_url_query["size"] = [str(default_emote_image_size)] emote_url_query["size"] = [str(default_emote_image_size)]
emote_url_query = urllib.parse.urlencode(emote_url_query, doseq=True) emote_url_query = urllib.parse.urlencode(emote_url_query, doseq=True)
emote_url = urllib.parse.urlunparse(emote_url._replace(query=emote_url_query)) emote_url = urllib.parse.urlunparse(emote_url._replace(query=emote_url_query))
common_script_utils.set_clipboard(emote_url) common_script_utils.set_clipboard(emote_url)
common_script_utils.send_notification( common_script_utils.send_notification(
os.path.basename(__file__), os.path.basename(__file__),
"copied URL of {} to clipboard!".format(chosen_emote["ref"]), "copied URL of {} to clipboard!".format(chosen_emote["ref"]),
) )

View file

@ -110,10 +110,11 @@ chosen_index = common_script_utils.run_chooser(
chooser_entries_iter(), prompt="bookmark" chooser_entries_iter(), prompt="bookmark"
) )
_title, url, _folder_path_str = chooser_entries[chosen_index] if chosen_index >= 0:
print(url) _title, url, _folder_path_str = chooser_entries[chosen_index]
print(url)
common_script_utils.set_clipboard(url) common_script_utils.set_clipboard(url)
common_script_utils.send_notification( common_script_utils.send_notification(
os.path.basename(__file__), "bookmark URL copied to clipboard!", url os.path.basename(__file__), "bookmark URL copied to clipboard!", url
) )