From e8b3745c916ec78f4b7a6232ebb55682a06ef8f0 Mon Sep 17 00:00:00 2001 From: Hassan Abouelela Date: Fri, 28 Oct 2022 02:29:56 +0400 Subject: Implicitly Close Client Using `with` Signed-off-by: Hassan Abouelela --- pydis_site/apps/content/utils.py | 41 +++++++++++++++++++--------------------- 1 file changed, 19 insertions(+), 22 deletions(-) diff --git a/pydis_site/apps/content/utils.py b/pydis_site/apps/content/utils.py index 5fa6353c..8c9ad036 100644 --- a/pydis_site/apps/content/utils.py +++ b/pydis_site/apps/content/utils.py @@ -75,30 +75,27 @@ def fetch_tags() -> list[Tag]: The entire repository is downloaded and extracted locally because getting file content would require one request per file, and can get rate-limited. """ - client = github_client() - - # Grab metadata - metadata = client.get("/repos/python-discord/bot/contents/bot/resources") - metadata.raise_for_status() - - hashes = {} - for entry in metadata.json(): - if entry["type"] == "dir": - # Tag group - files = client.get(entry["url"]) - files.raise_for_status() - files = files.json() - else: - files = [entry] - - for file in files: - hashes[file["name"]] = file["sha"] + with github_client() as client: + # Grab metadata + metadata = client.get("/repos/python-discord/bot/contents/bot/resources") + metadata.raise_for_status() + + hashes = {} + for entry in metadata.json(): + if entry["type"] == "dir": + # Tag group + files = client.get(entry["url"]) + files.raise_for_status() + files = files.json() + else: + files = [entry] - # Download the files - tar_file = client.get("/repos/python-discord/bot/tarball") - tar_file.raise_for_status() + for file in files: + hashes[file["name"]] = file["sha"] - client.close() + # Download the files + tar_file = client.get("/repos/python-discord/bot/tarball") + tar_file.raise_for_status() tags = [] with tempfile.TemporaryDirectory() as folder: -- cgit v1.2.3