mirror of
https://github.com/ldericher/fftcgtool
synced 2025-01-15 06:53:00 +00:00
some error handling
This commit is contained in:
parent
27af422ca8
commit
1e04e9f080
2 changed files with 10 additions and 2 deletions
|
@ -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
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue