From c36c9d258498c67016b14794faa2a008c26d76d3 Mon Sep 17 00:00:00 2001 From: Ethan Dalool Date: Sun, 16 Feb 2020 09:50:46 -0800 Subject: [PATCH] Use voussoirkit getpermission. --- getcrx.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/getcrx.py b/getcrx.py index 9174757..5824842 100644 --- a/getcrx.py +++ b/getcrx.py @@ -9,6 +9,7 @@ import traceback import zipfile from voussoirkit import clipext +from voussoirkit import getpermission FILENAME_BADCHARS = '\\/:*?<>|"' @@ -20,10 +21,6 @@ def sanitize_filename(name): name = name.replace(c, '-') return name -def prompt_permission(prompt): - answer = input(prompt) - return answer.lower() in {'yes', 'y'} - def get_webstore_name_version(extension_id): url = WEBSTORE_URL.format(extension_id=extension_id) response = requests.get(url) @@ -79,9 +76,11 @@ def getcrx(extension_id, auto_overwrite=None): crx_filename = sanitize_filename(crx_filename) if os.path.isfile(crx_filename): + if auto_overwrite is True: + permission = True if auto_overwrite is None: - message = '"%s" already exists. Overwrite?' % crx_filename - permission = prompt_permission(message) + message = f'"{crx_filename}" already exists. Overwrite?' + permission = getpermission.getpermission(message) else: permission = False else: @@ -90,7 +89,7 @@ def getcrx(extension_id, auto_overwrite=None): if permission: crx_handle = open(crx_filename, 'wb') crx_handle.write(response.content) - print('Downloaded "%s".' % crx_filename) + print(f'Downloaded "{crx_filename}".') def getcrx_argparse(args): extension_ids = []