mirror of
https://github.com/ldericher/fftcgtool
synced 2025-01-15 15:02:59 +00:00
subcommands
This commit is contained in:
parent
f7b9573998
commit
ab3e9deb7b
2 changed files with 89 additions and 36 deletions
|
@ -2,5 +2,6 @@ from .book import Book
|
|||
from .card import Card
|
||||
from .carddb import CardDB
|
||||
from .opus import Opus
|
||||
from .ttsdeck import TTSDeck
|
||||
|
||||
__all__ = ["Book", "Opus", "Card", "CardDB"]
|
||||
__all__ = ["Book", "Card", "CardDB", "Opus", "TTSDeck"]
|
||||
|
|
122
main.py
122
main.py
|
@ -6,41 +6,10 @@ import os
|
|||
import fftcg
|
||||
|
||||
|
||||
def main() -> None:
|
||||
# set up CLI
|
||||
parser = argparse.ArgumentParser(
|
||||
description="Imports FFTCG cards for TT-Sim.",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"opus_id",
|
||||
default="promo",
|
||||
metavar="Opus_ID",
|
||||
nargs="?",
|
||||
help="the Opus to import",
|
||||
)
|
||||
|
||||
parser.add_argument(
|
||||
"-n", "--num_threads",
|
||||
type=int,
|
||||
default=20,
|
||||
metavar="COUNT",
|
||||
help="maximum number of concurrent requests",
|
||||
)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
# set up logging
|
||||
logging.basicConfig(level=logging.INFO, format="%(levelname)s: %(processName)s %(message)s")
|
||||
|
||||
# output directory
|
||||
if not os.path.exists("out"):
|
||||
os.mkdir("out")
|
||||
os.chdir("out")
|
||||
|
||||
# main program
|
||||
def opus_decks(args: argparse.Namespace) -> list[fftcg.TTSDeck]:
|
||||
# import an opus
|
||||
opus = fftcg.Opus(args.opus_id)
|
||||
book = fftcg.Book(opus, "eg", args.num_threads)
|
||||
book = fftcg.Book(opus, "eg", args.num_requests)
|
||||
book.save()
|
||||
|
||||
# load the current carddb
|
||||
|
@ -48,7 +17,90 @@ def main() -> None:
|
|||
carddb.load()
|
||||
|
||||
# create elemental decks for opus
|
||||
for deck in opus.elemental_decks:
|
||||
return opus.elemental_decks
|
||||
|
||||
|
||||
def ffdecks_deck(args: argparse.Namespace) -> list[fftcg.TTSDeck]:
|
||||
# load the current carddb
|
||||
carddb = fftcg.CardDB.get()
|
||||
carddb.load()
|
||||
|
||||
# import a deck
|
||||
return [fftcg.TTSDeck.from_ffdecks_deck(args.deck_id)]
|
||||
|
||||
|
||||
def main() -> None:
|
||||
# set up CLI
|
||||
|
||||
# main parser
|
||||
parser = argparse.ArgumentParser(
|
||||
prog="fftcgtool",
|
||||
description="Imports FFTCG cards for TT-Sim.",
|
||||
)
|
||||
|
||||
subparsers = parser.add_subparsers(
|
||||
description="Import either an Opus to extend the mod, or import a deck to play right away.",
|
||||
dest="subcommand",
|
||||
help="valid subcommands",
|
||||
required=True,
|
||||
)
|
||||
|
||||
# "opus" subcommand
|
||||
opus_parser = subparsers.add_parser(
|
||||
"opus",
|
||||
description="Imports an Opus from the square API and creates its elemental decks as JSON files.",
|
||||
)
|
||||
|
||||
opus_parser.set_defaults(
|
||||
func=opus_decks
|
||||
)
|
||||
|
||||
opus_parser.add_argument(
|
||||
"opus_id",
|
||||
type=str,
|
||||
metavar="Opus_ID",
|
||||
help="the Opus to import",
|
||||
)
|
||||
|
||||
opus_parser.add_argument(
|
||||
"-n", "--num_requests",
|
||||
type=int,
|
||||
default=20,
|
||||
metavar="COUNT",
|
||||
help="maximum number of concurrent requests",
|
||||
)
|
||||
|
||||
# "deck" subcommand
|
||||
deck_parser = subparsers.add_parser(
|
||||
"deck",
|
||||
description="Imports a Deck from the ffdecks.com API and creates it as a JSON file.",
|
||||
)
|
||||
|
||||
deck_parser.set_defaults(
|
||||
func=ffdecks_deck
|
||||
)
|
||||
|
||||
deck_parser.add_argument(
|
||||
"deck_id",
|
||||
type=str,
|
||||
metavar="Deck_ID",
|
||||
help="the Deck to import",
|
||||
)
|
||||
|
||||
# set up logging
|
||||
logging.basicConfig(
|
||||
level=logging.INFO,
|
||||
format="%(levelname)s: %(processName)s %(message)s",
|
||||
)
|
||||
|
||||
# output directory
|
||||
if not os.path.exists("out"):
|
||||
os.mkdir("out")
|
||||
os.chdir("out")
|
||||
|
||||
# call function based on args
|
||||
args = parser.parse_args()
|
||||
for deck in args.func(args):
|
||||
deck.save()
|
||||
|
||||
# bye
|
||||
|
|
Loading…
Reference in a new issue