mirror of
https://github.com/ldericher/fftcgtool
synced 2025-01-15 15:02:59 +00:00
fix upload prompt
This commit is contained in:
parent
9d5412a12c
commit
b99dc00499
2 changed files with 42 additions and 11 deletions
|
@ -6,39 +6,68 @@ import pickle
|
|||
from .card import Card
|
||||
from .cards import Cards
|
||||
from .code import Code
|
||||
from .language import API_LANGS
|
||||
from .utils import CARDDB_FILE_NAME
|
||||
|
||||
|
||||
class CardDB:
|
||||
__instance: CardDB = None
|
||||
__content: dict[Code, Card]
|
||||
__cards: dict[Code, Card]
|
||||
__face_to_url: dict[str, str]
|
||||
|
||||
def __new__(cls) -> CardDB:
|
||||
if CardDB.__instance is None:
|
||||
CardDB.__instance = object.__new__(cls)
|
||||
CardDB.__instance.__content = {}
|
||||
CardDB.__instance.__cards = {}
|
||||
CardDB.__instance.__face_to_url = {}
|
||||
|
||||
return CardDB.__instance
|
||||
|
||||
def __contains__(self, item: Code) -> bool:
|
||||
return item in self.__content
|
||||
return item in self.__cards
|
||||
|
||||
def __getitem__(self, code: Code) -> Card:
|
||||
return self.__content[code]
|
||||
return self.__cards[code]
|
||||
|
||||
def __pickle(self):
|
||||
# pickle db file
|
||||
with bz2.BZ2File(CARDDB_FILE_NAME, "w") as file:
|
||||
pickle.dump(self.__cards, file)
|
||||
pickle.dump(self.__face_to_url, file)
|
||||
|
||||
def update(self, cards: Cards):
|
||||
for card in cards:
|
||||
self.__content[card.code] = card
|
||||
self.__cards[card.code] = card
|
||||
|
||||
# pickle db file
|
||||
with bz2.BZ2File(CARDDB_FILE_NAME, "w") as file:
|
||||
pickle.dump(self.__content, file)
|
||||
self.__pickle()
|
||||
|
||||
def load(self) -> None:
|
||||
def upload_prompt(self) -> None:
|
||||
faces = list(set([
|
||||
card[lang].face
|
||||
for card in self.__cards.values()
|
||||
for lang in API_LANGS
|
||||
if card[lang].face
|
||||
]))
|
||||
faces.sort()
|
||||
|
||||
for face in faces:
|
||||
if face not in self.__face_to_url:
|
||||
face_url = input(f"Upload '{face}' and paste URL: ")
|
||||
if face_url:
|
||||
self.__face_to_url[face] = face_url
|
||||
|
||||
self.__pickle()
|
||||
|
||||
def __unpickle(self):
|
||||
# unpickle db file
|
||||
self.__content.clear()
|
||||
self.__cards.clear()
|
||||
self.__face_to_url.clear()
|
||||
try:
|
||||
with bz2.BZ2File(CARDDB_FILE_NAME, "r") as file:
|
||||
self.__content |= pickle.load(file)
|
||||
self.__cards |= pickle.load(file)
|
||||
self.__face_to_url |= pickle.load(file)
|
||||
except FileNotFoundError:
|
||||
pass
|
||||
|
||||
def load(self) -> None:
|
||||
self.__unpickle()
|
||||
|
|
2
main.py
2
main.py
|
@ -24,6 +24,8 @@ def opus_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]:
|
|||
carddb.update(opus)
|
||||
decks.extend(opus.elemental_decks)
|
||||
|
||||
carddb.upload_prompt()
|
||||
|
||||
# create elemental decks for opus
|
||||
return decks
|
||||
|
||||
|
|
Loading…
Reference in a new issue