hp_cmd.py 1.67 KB
import sys

from run import generate_csv_file_if_needed, init_console_logger, config, get_default_sta_sto
from datetime import datetime
import argparse

if __name__ == "__main__":
    hp_parser = argparse.ArgumentParser(prog='Descritpor',
                                        description='description')

    hp_parser.add_argument('-clog', '--console-log', action='store_true')
    hp_parser.add_argument('-s', '--dry-run', action='store_true')

    subparsers = hp_parser.add_subparsers(dest='hpcmd_name')

    csvgen_parser = subparsers.add_parser('csv_gen',
                                          help='csv-gen help')
    csvgen_parser.add_argument('-a', '--all', action='store_true')
    csvgen_parser.add_argument('-t', '--target')
    csvgen_parser.add_argument('-i', '--input')
    csvgen_parser.add_argument('-b', '--begin')
    csvgen_parser.add_argument('-e', '--end')

    args = hp_parser.parse_args()

    if args.console_log:
        _logger = init_console_logger()

    if args.hpcmd_name == 'csv_gen':
        # build default dates in not -b or not -e
        sta, sto = get_default_sta_sto( args.begin, args.end)

        if args.all:
            # build the {target_slug: [input list]} dictionnary from config.yaml
            targets = {t['slug']: list(t['models'].keys()) for t in config['targets']}
        else:
            # todo: check -i an -t
            targets = {args.target: [args.input]}

        for _t, _i_list in targets.items():
            # print(_t, _i_list)
            for _i in _i_list:
                print(f"generating csv for {_t}/ {_i}")
                if args.dry_run:
                    continue
                generate_csv_file_if_needed(_t, _i, sta, sto)