mirror of
https://github.com/ldericher/fftcgtool
synced 2025-01-15 15:02:59 +00:00
eafp principle
This commit is contained in:
parent
5fa2caec0f
commit
f5d7e7dedf
3 changed files with 20 additions and 10 deletions
|
@ -31,11 +31,16 @@ class CardDB:
|
|||
|
||||
def __init__(self, db_url: str = None):
|
||||
if db_url is not None:
|
||||
res = requests.get(db_url, stream=True)
|
||||
if not res.ok:
|
||||
raise ValueError("Invalid URL given to CardDB!")
|
||||
try:
|
||||
with open(db_url, "rb") as db_file:
|
||||
self._load(db_file)
|
||||
|
||||
self._load(io.BytesIO(res.content))
|
||||
except FileNotFoundError:
|
||||
res = requests.get(db_url, stream=True)
|
||||
if not res.ok:
|
||||
raise ValueError("Invalid URL given to CardDB!")
|
||||
|
||||
self._load(io.BytesIO(res.content))
|
||||
|
||||
def _load(self, db: str | PathLike[str] | IO[bytes]):
|
||||
try:
|
||||
|
@ -60,9 +65,9 @@ class CardDB:
|
|||
return self._cards[code]
|
||||
|
||||
def get_face_url(self, face: str) -> str:
|
||||
if face in self._face_to_url:
|
||||
try:
|
||||
return self._face_to_url[face]
|
||||
else:
|
||||
except KeyError:
|
||||
return face
|
||||
|
||||
def save(self) -> None:
|
||||
|
|
|
@ -73,10 +73,13 @@ class Opus(Cards):
|
|||
self.sort(key=lambda x: x.code.opus)
|
||||
|
||||
for card in self:
|
||||
if card.code in carddb:
|
||||
try:
|
||||
for lang in API_LANGS:
|
||||
card[lang] = replace(card[lang], face=carddb[card.code][lang].face)
|
||||
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
logger.debug(f"imported card {card}")
|
||||
|
||||
@property
|
||||
|
|
|
@ -77,9 +77,9 @@ class TTSDeck(Cards):
|
|||
"Backup": 5,
|
||||
}
|
||||
|
||||
if data["type"] in key_prios:
|
||||
try:
|
||||
return key_prios[data["type"]]
|
||||
else:
|
||||
except KeyError:
|
||||
return 4
|
||||
|
||||
def by_cost(data: dict[str, str | int]) -> int:
|
||||
|
@ -125,8 +125,10 @@ class TTSDeck(Cards):
|
|||
|
||||
# replace with normal-art cards
|
||||
for card in deck_cards:
|
||||
if card["code"] in replace_full_arts:
|
||||
try:
|
||||
card["code"] = replace_full_arts[card["code"]]
|
||||
except KeyError:
|
||||
pass
|
||||
|
||||
codes = [
|
||||
# create list of code objects
|
||||
|
|
Loading…
Reference in a new issue