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

eafp principle

This commit is contained in:
Jörn-Michael Miehe 2021-09-13 02:29:02 +02:00
parent 5fa2caec0f
commit f5d7e7dedf
3 changed files with 20 additions and 10 deletions

View file

@ -31,6 +31,11 @@ class CardDB:
def __init__(self, db_url: str = None): def __init__(self, db_url: str = None):
if db_url is not None: if db_url is not None:
try:
with open(db_url, "rb") as db_file:
self._load(db_file)
except FileNotFoundError:
res = requests.get(db_url, stream=True) res = requests.get(db_url, stream=True)
if not res.ok: if not res.ok:
raise ValueError("Invalid URL given to CardDB!") raise ValueError("Invalid URL given to CardDB!")
@ -60,9 +65,9 @@ class CardDB:
return self._cards[code] return self._cards[code]
def get_face_url(self, face: str) -> str: def get_face_url(self, face: str) -> str:
if face in self._face_to_url: try:
return self._face_to_url[face] return self._face_to_url[face]
else: except KeyError:
return face return face
def save(self) -> None: def save(self) -> None:

View file

@ -73,10 +73,13 @@ class Opus(Cards):
self.sort(key=lambda x: x.code.opus) self.sort(key=lambda x: x.code.opus)
for card in self: for card in self:
if card.code in carddb: try:
for lang in API_LANGS: for lang in API_LANGS:
card[lang] = replace(card[lang], face=carddb[card.code][lang].face) card[lang] = replace(card[lang], face=carddb[card.code][lang].face)
except KeyError:
pass
logger.debug(f"imported card {card}") logger.debug(f"imported card {card}")
@property @property

View file

@ -77,9 +77,9 @@ class TTSDeck(Cards):
"Backup": 5, "Backup": 5,
} }
if data["type"] in key_prios: try:
return key_prios[data["type"]] return key_prios[data["type"]]
else: except KeyError:
return 4 return 4
def by_cost(data: dict[str, str | int]) -> int: def by_cost(data: dict[str, str | int]) -> int:
@ -125,8 +125,10 @@ class TTSDeck(Cards):
# replace with normal-art cards # replace with normal-art cards
for card in deck_cards: for card in deck_cards:
if card["code"] in replace_full_arts: try:
card["code"] = replace_full_arts[card["code"]] card["code"] = replace_full_arts[card["code"]]
except KeyError:
pass
codes = [ codes = [
# create list of code objects # create list of code objects