From a14eb56c33b409dd361e5da8b1940dead9b5c125 Mon Sep 17 00:00:00 2001 From: LDericher <40151420+ldericher@users.noreply.github.com> Date: Mon, 6 Sep 2021 04:41:49 +0200 Subject: [PATCH] requests unification --- fftcg/imageloader.py | 2 +- fftcg/ttsdeck.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/fftcg/imageloader.py b/fftcg/imageloader.py index 51f52b9..458956d 100644 --- a/fftcg/imageloader.py +++ b/fftcg/imageloader.py @@ -31,7 +31,7 @@ class ImageLoader: pass # if rejected, substitute the english version - if not res.status_code == 200: + if not res.ok: logger.warning(f"falling back to english version of {url}") return cls._load_inner((base_url, code, FALLBACK_LANGUAGE.image_suffix)) diff --git a/fftcg/ttsdeck.py b/fftcg/ttsdeck.py index 6998b91..c1a150f 100644 --- a/fftcg/ttsdeck.py +++ b/fftcg/ttsdeck.py @@ -66,9 +66,9 @@ class TTSDeck(Cards): deck_id = match.groups()[3] # api request - req = requests.get(TTSDeck.__FFDECKS_API_URL, params={"deck_id": deck_id}) + res = requests.get(TTSDeck.__FFDECKS_API_URL, params={"deck_id": deck_id}) - if req.status_code != 200: + if not res.ok: logger.error("Invalid Deck ID for FFDecks API!") return cls([], "", "", True) @@ -80,7 +80,7 @@ class TTSDeck(Cards): "type": card["card"]["type"], "cost": int(card["card"]["cost"]), "count": int(card["quantity"]), - } for card in req.json()["cards"]] + } for card in res.json()["cards"]] # sort cards by type, then by cost def by_type(data: dict[str, str | int]) -> int: @@ -125,7 +125,7 @@ class TTSDeck(Cards): ] # general metadata - name = f"{req.json()['name']}" + name = f"{res.json()['name']}" description = deck_id # create deck object