recopytex/recopytex.py

56 lines
1.2 KiB
Python
Raw Normal View History

2019-08-04 14:25:44 +00:00
#!/usr/bin/env python
# encoding: utf-8
import click
from pathlib import Path
import yaml
import sys
import papermill as pm
with open("recoconfig.yml", "r") as config:
config = yaml.load(config, Loader=yaml.FullLoader)
@click.group()
def cli():
pass
@cli.command()
def print_config():
click.echo(config.key())
@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)
csv_filename = csv_file.name.split(".")[0]
assessment = str(csv_filename).split("_")[-1].capitalize()
tribe = str(csv_file.parent).split("/")[-1]
2019-08-04 14:25:44 +00:00
template = Path(config["templates"]) / "tpl_evaluation.ipynb"
dest = Path(config["output"]) / tribe / csv_filename / f"{assessment}.ipynb"
2019-08-04 14:25:44 +00:00
dest.parent.mkdir(parents=True, exist_ok=True)
pm.execute_notebook(
str(template),
str(dest),
parameters=dict(
tribe=tribe, assessment=assessment, csv_file=str(csv_file.absolute())
),
2019-08-04 14:25:44 +00:00
)
if __name__ == "__main__":
cli()