From fe3280b91d6f1ab28043a571e88a657cf0652b9e Mon Sep 17 00:00:00 2001 From: Bertrand Benjamin Date: Tue, 17 Sep 2019 19:29:43 +0200 Subject: [PATCH] Feat: Process all csv if nothing is specify --- recopytex/scripts/recopytex.py | 42 +++++++++++++++++++++++----------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/recopytex/scripts/recopytex.py b/recopytex/scripts/recopytex.py index 83885e0..8bb12b2 100644 --- a/recopytex/scripts/recopytex.py +++ b/recopytex/scripts/recopytex.py @@ -26,18 +26,8 @@ def print_config(): click.echo(config) -@cli.command() -@click.argument("csv_file") -def report(csv_file): - csv = Path(csv_file) - if not csv.exists(): - click.echo(f"{csv_file} does not exists") - sys.exit(1) - if csv.suffix != ".csv": - click.echo(f"{csv_file} has to be a csv file") - sys.exit(1) - - csv_file = Path(csv_file) +def reporting(csv_file): + #csv_file = Path(csv_file) tribe_dir = csv_file.parent csv_filename = csv_file.name.split(".")[0] @@ -46,7 +36,7 @@ def report(csv_file): try: date = datetime.strptime(date, "%y%m%d") except ValueError: - date = None + date = datetime.today().strptime(date, "%y%m%d") tribe = str(tribe_dir).split("/")[-1] @@ -64,6 +54,32 @@ def report(csv_file): ), ) +@cli.command() +@click.argument("csv_file", required=False) +def report(csv_file=""): + if csv_file: + csv = Path(csv_file) + if not csv.exists(): + click.echo(f"{csv_file} does not exists") + sys.exit(1) + if csv.suffix != ".csv": + click.echo(f"{csv_file} has to be a csv file") + sys.exit(1) + csvs = [csv] + else: + csvs = list(Path(config["source"]).glob('**/*.csv')) + + for csv in csvs: + click.echo(f"Processing {csv}") + try: + reporting(csv) + except pm.exceptions.PapermillExecutionError as e: + click.echo(f"Error with {csv}: {e}") + + + + + # with open(csv_file.parent / "description.yml") as f: # tribe_desc = yaml.load(f, Loader=yaml.FullLoader)