Format tools/download_tool.py

This commit is contained in:
Luke Street 2025-08-15 10:42:49 -06:00
parent b4be7cfa39
commit 49b34faa6a

View File

@ -91,6 +91,7 @@ TOOLS: Dict[str, Callable[[str], str]] = {
"wibo": wibo_url, "wibo": wibo_url,
} }
def download(url, response, output) -> None: def download(url, response, output) -> None:
if url.endswith(".zip"): if url.endswith(".zip"):
data = io.BytesIO(response.read()) data = io.BytesIO(response.read())
@ -107,6 +108,7 @@ def download(url, response, output) -> None:
st = os.stat(output) st = os.stat(output)
os.chmod(output, st.st_mode | stat.S_IEXEC) os.chmod(output, st.st_mode | stat.S_IEXEC)
def main() -> None: def main() -> None:
parser = argparse.ArgumentParser() parser = argparse.ArgumentParser()
parser.add_argument("tool", help="Tool name") parser.add_argument("tool", help="Tool name")
@ -128,12 +130,17 @@ def main() -> None:
try: try:
import certifi import certifi
import ssl import ssl
except: except ImportError:
print("\"certifi\" module not found. Please install it using \"python -m pip install certifi\".") print(
'"certifi" module not found. Please install it using "python -m pip install certifi".'
)
return return
with urllib.request.urlopen(req, context=ssl.create_default_context(cafile=certifi.where())) as response: with urllib.request.urlopen(
req, context=ssl.create_default_context(cafile=certifi.where())
) as response:
download(url, response, output) download(url, response, output)
if __name__ == "__main__": if __name__ == "__main__":
main() main()