diff options
| author | 2022-10-28 02:29:56 +0400 | |
|---|---|---|
| committer | 2022-10-28 02:29:56 +0400 | |
| commit | e8b3745c916ec78f4b7a6232ebb55682a06ef8f0 (patch) | |
| tree | 76e239105196d9147723d4c5c662f75293700589 /pydis_site/apps/content | |
| parent | Use `casefold` Instead Of `lower` (diff) | |
Implicitly Close Client Using `with`
Signed-off-by: Hassan Abouelela <[email protected]>
Diffstat (limited to 'pydis_site/apps/content')
| -rw-r--r-- | pydis_site/apps/content/utils.py | 41 | 
1 files 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:  |