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

general quality

This commit is contained in:
Jörn-Michael Miehe 2021-09-03 09:29:40 +02:00
parent 0f176f44ea
commit fce795ce53
5 changed files with 31 additions and 23 deletions

View file

@ -20,12 +20,12 @@ class Book:
for card in cards for card in cards
] ]
# card back URL # card back URL
urls.append((CARD_BACK_URL, "", "")) urls.insert(0, (CARD_BACK_URL, "", ""))
# multi-threaded download # multi-threaded download
images = ImageLoader.load(urls, num_threads) images = iter(ImageLoader.load(urls, num_threads))
# card back Image # card back Image
back_image = images.pop(-1) back_image = next(images)
self.__pages = [] self.__pages = []
@ -63,5 +63,6 @@ class Book:
# save images # save images
for page in self.__pages: for page in self.__pages:
page["file_name"] = os.path.join(IMAGES_DIR_NAME, page["file_name"]) page["image"].save(
page["image"].save(page["file_name"]) os.path.join(IMAGES_DIR_NAME, page["file_name"])
)

View file

@ -1,6 +1,6 @@
import logging import logging
from dataclasses import replace from dataclasses import replace
from typing import Callable, Iterator from typing import Callable, Iterable
import requests import requests
import roman import roman
@ -41,6 +41,8 @@ class Opus(Cards):
self.__filename = "?" self.__filename = "?"
params = {"set": "?"} params = {"set": "?"}
logger.info(f"Importing Opus {self.__number}")
# required params: # required params:
# text # text
# supported params: # supported params:
@ -82,7 +84,7 @@ class Opus(Cards):
return self.__number return self.__number
@property @property
def elemental_decks(self) -> Iterator[TTSDeck]: def elemental_decks(self) -> Iterable[TTSDeck]:
if self.number in ["PR", "B"]: if self.number in ["PR", "B"]:
return [TTSDeck( return [TTSDeck(
codes=[ codes=[

View file

@ -72,6 +72,8 @@ class TTSDeck(Cards):
logger.error("Invalid Deck ID for FFDecks API!") logger.error("Invalid Deck ID for FFDecks API!")
return cls([], "", "", True) return cls([], "", "", True)
logger.info(f"Importing Deck {deck_id}")
# pre-extract the used data # pre-extract the used data
deck_cards = [{ deck_cards = [{
"code": card["card"]["serial_number"], "code": card["card"]["serial_number"],

View file

@ -1,4 +1,5 @@
from typing import Iterator import itertools
from typing import Iterator, Generator, Iterable
from PIL import Image from PIL import Image
@ -39,13 +40,17 @@ def encircle_symbol(symbol: str, negative: bool) -> str:
return chr(ord(base_symbols[1]) + symbol_num) return chr(ord(base_symbols[1]) + symbol_num)
def chunks(chunk_size: int, whole: list) -> Iterator[list]: def chunks(chunk_size: int, whole: Iterable) -> Generator[Iterator, None, None]:
# while there are elements it = iter(whole)
while whole: # get chunk
# get a chunk while chunk := itertools.islice(it, chunk_size):
yield whole[:chunk_size] # stop if no first element was found
# remove that chunk try:
whole = whole[chunk_size:] first_el = next(chunk)
except StopIteration:
return
# reattach first element
yield itertools.chain((first_el,), chunk)
def grid_paste(page: Image.Image, index: int, card: Image.Image) -> None: def grid_paste(page: Image.Image, index: int, card: Image.Image) -> None:

View file

@ -12,10 +12,7 @@ OUT_DIR_NAME = "out" # name of output directory
def opus_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]: def opus_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]:
# load the current carddb
carddb = fftcg.CardDB() carddb = fftcg.CardDB()
carddb.load()
decks: list[fftcg.TTSDeck] = [] decks: list[fftcg.TTSDeck] = []
for opus_id in args.opus_ids: for opus_id in args.opus_ids:
# import an opus # import an opus
@ -33,15 +30,11 @@ def opus_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]:
def ffdecks_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]: def ffdecks_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]:
# load the current carddb
carddb = fftcg.CardDB()
carddb.load()
decks: list[fftcg.TTSDeck] = [] decks: list[fftcg.TTSDeck] = []
for deck_id in args.deck_ids: for deck_id in args.deck_ids:
# import a deck
decks.append(fftcg.TTSDeck.from_ffdecks_deck(deck_id)) decks.append(fftcg.TTSDeck.from_ffdecks_deck(deck_id))
# import a deck
return decks return decks
@ -142,6 +135,7 @@ def main() -> None:
) )
logger = logging.getLogger(__name__) logger = logging.getLogger(__name__)
logger.info("fftcgtool started.")
logger.debug(f"{args = }") logger.debug(f"{args = }")
# output directory # output directory
@ -150,6 +144,10 @@ def main() -> None:
os.chdir(OUT_DIR_NAME) os.chdir(OUT_DIR_NAME)
# load the current carddb
carddb = fftcg.CardDB()
carddb.load()
# call function based on args # call function based on args
decks = args.func(args) decks = args.func(args)