From 29ce4e6f24c568380a937b711ac0481b3238422f Mon Sep 17 00:00:00 2001 From: LDericher <40151420+ldericher@users.noreply.github.com> Date: Mon, 9 Aug 2021 05:44:12 +0200 Subject: [PATCH] minor cleanup --- fftcg/book.py | 8 ++++---- fftcg/cards.py | 3 +++ fftcg/imageloader.py | 2 +- fftcg/opus.py | 13 ++++--------- 4 files changed, 12 insertions(+), 14 deletions(-) diff --git a/fftcg/book.py b/fftcg/book.py index a3fa142..163e4d6 100644 --- a/fftcg/book.py +++ b/fftcg/book.py @@ -48,9 +48,9 @@ class Book: # width, height per card w, h = resolution - def paste_image(page: Image, index: int, image: Image) -> None: + def paste_card(index: int, card: Image) -> None: x, y = (index % c) * w, (index // c) * h - page.paste(image, (x, y)) + page.paste(card, (x, y)) self.__pages = [] for images in chunks(images, grid_capacity): @@ -60,10 +60,10 @@ class Book: # paste card faces onto page for i, image in enumerate(images): - paste_image(page, i, image) + paste_card(i, image) # paste card back in last position - paste_image(page, c * r - 1, back_image) + paste_card(c * r - 1, back_image) self.__pages.append(page) diff --git a/fftcg/cards.py b/fftcg/cards.py index 801908c..7a391a6 100644 --- a/fftcg/cards.py +++ b/fftcg/cards.py @@ -16,6 +16,9 @@ class Cards(list[Card]): # [array] type, element, cost, rarity, power, category_1, set # [int] exactmatch=0|1 + if "text" not in params: + params["text"] = "" + req = requests.post(Cards.__API_URL, json=params) self.extend([Card(card_data) for card_data in req.json()["cards"]]) diff --git a/fftcg/imageloader.py b/fftcg/imageloader.py index 4242b97..dff2226 100644 --- a/fftcg/imageloader.py +++ b/fftcg/imageloader.py @@ -34,7 +34,7 @@ class ImageLoader(threading.Thread): image.convert("RGB") image = image.resize(self.__resolution, Image.BICUBIC) break - except: + except requests.exceptions.RequestException: pass # put image in correct position diff --git a/fftcg/opus.py b/fftcg/opus.py index e992e1c..0e79314 100644 --- a/fftcg/opus.py +++ b/fftcg/opus.py @@ -9,29 +9,24 @@ class Opus(Cards): def __init__(self, opus_id: str): logger = logging.getLogger(__name__) - params: dict[str, any] = { - "text": "", - # "element": ["darkness"], - } - if opus_id.isnumeric(): roman_opus_id = roman.toRoman(int(opus_id)) - params |= {"set": [f"Opus {roman_opus_id.upper()}"]} + params = {"set": [f"Opus {roman_opus_id.upper()}"]} self.__number = opus_id self.__name = f"opus_{opus_id}" elif opus_id == "chaos": - params |= {"set": ["Boss Deck Chaos"]} + params = {"set": ["Boss Deck Chaos"]} self.__number = "B" self.__name = "boss_deck_chaos" elif opus_id == "promo": - params |= {"rarity": ["pr"]} + params = {"rarity": ["pr"]} self.__number = "PR" self.__name = "promo" else: - params |= {"set": ["?"]} + params = {"set": ["?"]} self.__number = "?" self.__name = "?"