diff --git a/pdf_oralia/scripts.py b/pdf_oralia/scripts.py index b73d284..875875f 100644 --- a/pdf_oralia/scripts.py +++ b/pdf_oralia/scripts.py @@ -3,6 +3,7 @@ from logging.config import dictConfig from pathlib import Path import click +import pandas as pd from .extract import extract_save @@ -62,5 +63,20 @@ def all(folder, dest): @main.command() -def join(): - pass +@click.option("--folder", help="Tous les fichiers dans folder", default="./") +@click.option("--dest", help="Où mettre les fichiers produits", default="") +def join(folder, dest): + p = Path(folder) + dfs = { + "charge": [], + "locataire": [], + } + for file in p.glob("*.xlsx"): + year, month, immeuble, table = file.stem.split("_") + df = pd.read_excel(file).assign(annee=year, mois=month, immeuble=immeuble) + dfs[table].append(df) + for tablename, datas in dfs.items(): + df = pd.concat(datas) + destination = Path(dest) / f"{tablename}.xlsx" + df.to_excel(destination, index=False) + logging.info(f"{destination} written")