diff --git a/hanabi/hanabi_cli.py b/hanabi/hanabi_cli.py index 266a874..13872c8 100755 --- a/hanabi/hanabi_cli.py +++ b/hanabi/hanabi_cli.py @@ -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): diff --git a/hanabi/live/variants.py b/hanabi/live/variants.py index 27b3f36..770c0b0 100644 --- a/hanabi/live/variants.py +++ b/hanabi/live/variants.py @@ -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",