Feat: Process all csv if nothing is specify

This commit is contained in:
Bertrand Benjamin 2019-09-17 19:29:43 +02:00
parent 3e85c3829d
commit fe3280b91d

View File

@ -26,18 +26,8 @@ def print_config():
click.echo(config) click.echo(config)
@cli.command() def reporting(csv_file):
@click.argument("csv_file") #csv_file = Path(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)
tribe_dir = csv_file.parent tribe_dir = csv_file.parent
csv_filename = csv_file.name.split(".")[0] csv_filename = csv_file.name.split(".")[0]
@ -46,7 +36,7 @@ def report(csv_file):
try: try:
date = datetime.strptime(date, "%y%m%d") date = datetime.strptime(date, "%y%m%d")
except ValueError: except ValueError:
date = None date = datetime.today().strptime(date, "%y%m%d")
tribe = str(tribe_dir).split("/")[-1] 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: # with open(csv_file.parent / "description.yml") as f:
# tribe_desc = yaml.load(f, Loader=yaml.FullLoader) # tribe_desc = yaml.load(f, Loader=yaml.FullLoader)