From 1e04e9f0800260824e8f8255ed95debbf78bb137 Mon Sep 17 00:00:00 2001 From: LDericher <40151420+ldericher@users.noreply.github.com> Date: Tue, 14 Sep 2021 01:05:32 +0200 Subject: [PATCH] some error handling --- fftcgtool/ffdecks.py | 5 +++-- fftcgtool/utils.py | 7 +++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/fftcgtool/ffdecks.py b/fftcgtool/ffdecks.py index a78ce11..5bca6af 100644 --- a/fftcgtool/ffdecks.py +++ b/fftcgtool/ffdecks.py @@ -8,6 +8,7 @@ import requests from .code import Code from .ttsdeck import TTSDeck +from .utils import int_default def _sort_cards_by_type(data: dict[str, str | int]) -> int: @@ -62,8 +63,8 @@ class FFDecks(list[TTSDeck]): card_data = [{ "code": card["card"]["serial_number"], "type": card["card"]["type"], - "cost": int(card["card"]["cost"]), - "count": int(card["quantity"]), + "cost": int_default(card["card"]["cost"], 0), + "count": int_default(card["quantity"], 0), } for card in res.json()["cards"]] # sort cards by type, then by cost diff --git a/fftcgtool/utils.py b/fftcgtool/utils.py index 3c721b7..65038ed 100644 --- a/fftcgtool/utils.py +++ b/fftcgtool/utils.py @@ -56,3 +56,10 @@ def grid_paste(page: Image.Image, index: int, card: Image.Image) -> None: w, h = card.size position = (index % GRID.x) * w, (index // GRID.x) * h page.paste(card, position) + + +def int_default(integer: str, default: int) -> int: + try: + return int(integer) + except ValueError: + return default