Start of 5etools utilities and library
Copying over the bestiary from dnd_monster_stats and working on a similar SpellList object and Spell DB.
This commit is contained in:
@@ -0,0 +1,36 @@
|
||||
import argparse
|
||||
import os
|
||||
import re
|
||||
import pathlib
|
||||
|
||||
|
||||
def build_argument_parser(description: str) -> argparse.ArgumentParser:
|
||||
parser = argparse.ArgumentParser(description=description)
|
||||
parser.add_argument(
|
||||
"--data-dir",
|
||||
"-d",
|
||||
type=valid_directory,
|
||||
required=True,
|
||||
help="Data directory from 5etools",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--source-code",
|
||||
"-s",
|
||||
action="append",
|
||||
metavar="CODE",
|
||||
type=valid_source_code,
|
||||
help="Filter data to just the given sources, may be provided multiple times",
|
||||
)
|
||||
return parser
|
||||
|
||||
|
||||
def valid_directory(path: str) -> pathlib.Path:
|
||||
if os.path.isdir(path):
|
||||
return pathlib.Path(os.path.realpath(path))
|
||||
raise argparse.ArgumentTypeError(f"{path} is not a directory")
|
||||
|
||||
|
||||
def valid_source_code(code: str) -> str:
|
||||
if re.match(r"^[A-Z]+$", code) is None:
|
||||
raise argparse.ArgumentTypeError(f"{code} is not a valid data source code")
|
||||
return code
|
||||
@@ -0,0 +1,17 @@
|
||||
import pprint
|
||||
import dnd5etools.db.spells
|
||||
import dnd5etools.scripts.argparse
|
||||
|
||||
|
||||
def main():
|
||||
args = dnd5etools.scripts.argparse.build_argument_parser(
|
||||
"Summarizes spell templates",
|
||||
).parse_args()
|
||||
db = dnd5etools.db.spells.SpellsDb(args.data_dir)
|
||||
if args.source_code is None:
|
||||
codes = list(db.db_index.source_index.keys())
|
||||
else:
|
||||
codes = args.source_code
|
||||
for code in codes:
|
||||
spell_list = db.get_spell_list(code)
|
||||
pprint.pprint(spell_list.spells)
|
||||
Reference in New Issue
Block a user