1
0
Fork 0
mirror of https://github.com/ldericher/fftcgtool synced 2025-01-15 06:53:00 +00:00

some error handling

This commit is contained in:
Jörn-Michael Miehe 2021-09-14 01:05:32 +02:00
parent 27af422ca8
commit 1e04e9f080
2 changed files with 10 additions and 2 deletions

View file

@ -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

View file

@ -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