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

View file

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

View file

@ -72,6 +72,8 @@ class TTSDeck(Cards):
logger.error("Invalid Deck ID for FFDecks API!")
return cls([], "", "", True)
logger.info(f"Importing Deck {deck_id}")
# pre-extract the used data
deck_cards = [{
"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
@ -39,13 +40,17 @@ def encircle_symbol(symbol: str, negative: bool) -> str:
return chr(ord(base_symbols[1]) + symbol_num)
def chunks(chunk_size: int, whole: list) -> Iterator[list]:
# while there are elements
while whole:
# get a chunk
yield whole[:chunk_size]
# remove that chunk
whole = whole[chunk_size:]
def chunks(chunk_size: int, whole: Iterable) -> Generator[Iterator, None, None]:
it = iter(whole)
# get chunk
while chunk := itertools.islice(it, chunk_size):
# stop if no first element was found
try:
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:

View file

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