add cli option to download all games

This commit is contained in:
Maximilian Keßler 2023-07-05 18:48:33 +02:00
parent b3828baa5d
commit 8a2774bf93
Signed by: max
GPG Key ID: BCC5A619923C0BA5
2 changed files with 41 additions and 5 deletions

View File

@ -4,6 +4,7 @@ from typing import Optional
import verboselogs
from hanabi import logger, logger_manager
from hanabi.live import variants
from hanabi.live import check_game
from hanabi.live import download_data
from hanabi.live import compress
@ -54,11 +55,22 @@ def subcommand_init(force: bool, populate: bool):
logger.info("Successfully populated tables with variants and suits from hanab.live")
def subcommand_download(game_id: Optional[int], variant_id: Optional[int], export_all_games):
def subcommand_download(
game_id: Optional[int]
, variant_id: Optional[int]
, export_all: bool = False
, all_variants: bool = False
):
if game_id is not None:
download_data.detailed_export_game(game_id)
logger.info("Successfully exported game ")
if variant_id is not None:
download_data.download_games(variant_id, export_all_games)
download_data.download_games(variant_id, export_all)
logger.info("Successfully exported games for variant id {}".format(variant_id))
if all_variants:
for variant in variants.get_all_variant_ids():
download_data.download_games(variant, export_all)
logger.info("Successfully exported games for all variants")
def add_init_subparser(subparsers):
@ -78,9 +90,25 @@ def add_init_subparser(subparsers):
def add_download_subparser(subparsers):
parser = subparsers.add_parser('download', help='Download games from hanab.live')
group = parser.add_mutually_exclusive_group(required=True)
group.add_argument('--var', '--variant', '-v', type=int, dest='variant_id')
group.add_argument('--id', '-i', type=int, dest='game_id')
parser.add_argument('--all-games', '-a', action='store_true', dest='export_all_games')
group.add_argument(
'--var', '--variant', '-v',
type=int,
dest='variant_id',
help='Download information on all games given variant id (but not necessarily export all of them)'
)
group.add_argument('--id', '-i', type=int, dest='game_id', help='Download single game given id')
group.add_argument(
'--all-variants', '-a',
action='store_true',
dest='all_variants',
help='Download information from games on all variants (but not necessarily export all of them)'
)
parser.add_argument(
'--export-all', '-e',
action='store_true',
dest='export_all',
help='Export all games specified in full detail (i.e. also actions and game options)'
)
def add_analyze_subparser(subparsers):

View File

@ -15,6 +15,14 @@ def variant_id(name) -> Optional[int]:
return var_id[0]
def get_all_variant_ids() -> List[int]:
cur.execute(
"SELECT id FROM variants "
"ORDER BY id"
)
return [var_id for (var_id,) in cur.fetchall()]
def variant_name(var_id) -> Optional[int]:
cur.execute(
"SELECT name FROM variants WHERE id = %s",