2022-09-28 07:56:35 +00:00
|
|
|
import logging
|
|
|
|
from logging.config import dictConfig
|
2022-09-27 12:48:41 +00:00
|
|
|
from pathlib import Path
|
2022-09-27 13:01:14 +00:00
|
|
|
|
2022-09-27 12:48:41 +00:00
|
|
|
import click
|
|
|
|
|
2022-09-27 14:01:09 +00:00
|
|
|
from .extract import extract_save
|
2023-10-05 13:10:39 +00:00
|
|
|
from .join import join_excel
|
2022-09-27 12:48:41 +00:00
|
|
|
|
2022-09-28 07:56:35 +00:00
|
|
|
logging_config = dict(
|
|
|
|
version=1,
|
|
|
|
formatters={"f": {"format": "%(levelname)-8s %(name)-12s %(message)s"}},
|
|
|
|
handlers={
|
|
|
|
"h": {
|
|
|
|
"class": "logging.StreamHandler",
|
|
|
|
"formatter": "f",
|
|
|
|
"level": logging.DEBUG,
|
|
|
|
}
|
|
|
|
},
|
|
|
|
root={
|
|
|
|
"handlers": ["h"],
|
|
|
|
"level": logging.DEBUG,
|
|
|
|
},
|
|
|
|
)
|
|
|
|
|
|
|
|
dictConfig(logging_config)
|
|
|
|
|
2022-09-27 12:48:41 +00:00
|
|
|
|
2022-09-27 14:01:09 +00:00
|
|
|
@click.group()
|
|
|
|
def main():
|
|
|
|
pass
|
2022-09-27 12:48:41 +00:00
|
|
|
|
|
|
|
|
2022-09-27 14:01:09 +00:00
|
|
|
@main.group()
|
|
|
|
def extract():
|
|
|
|
pass
|
2022-09-27 12:48:41 +00:00
|
|
|
|
|
|
|
|
2022-09-27 14:01:09 +00:00
|
|
|
@extract.command()
|
2022-09-27 19:13:58 +00:00
|
|
|
@click.argument("pdf_file", required=1)
|
2022-09-28 03:33:09 +00:00
|
|
|
@click.option("--dest", help="Où mettre les fichiers produits", default="")
|
|
|
|
def on(pdf_file, dest):
|
|
|
|
if not dest:
|
|
|
|
pdf_path = Path(pdf_file)
|
|
|
|
dest = pdf_path.parent
|
|
|
|
|
|
|
|
extract_save(pdf_file, dest)
|
2022-09-27 12:48:41 +00:00
|
|
|
|
|
|
|
|
2022-09-27 14:01:09 +00:00
|
|
|
@extract.command()
|
2022-10-10 20:15:21 +00:00
|
|
|
@click.option("--src", help="Tous les fichiers dans folder", default="./")
|
2022-09-27 14:01:09 +00:00
|
|
|
@click.option("--dest", help="Où mettre les fichiers produits", default="./")
|
2022-12-18 09:00:33 +00:00
|
|
|
def all(src, dest):
|
|
|
|
p = Path(src)
|
2022-09-27 12:48:41 +00:00
|
|
|
|
2022-09-27 14:01:09 +00:00
|
|
|
d = Path(dest)
|
|
|
|
d.mkdir(exist_ok=True)
|
2022-09-27 13:01:14 +00:00
|
|
|
|
2022-09-27 14:01:09 +00:00
|
|
|
pdf_files = [x for x in p.iterdir() if ".pdf" in str(x)]
|
|
|
|
for pdf_file in pdf_files:
|
2022-09-28 07:56:35 +00:00
|
|
|
logging.info(f"Found {pdf_file}")
|
2022-09-27 14:01:09 +00:00
|
|
|
extract_save(pdf_file, d)
|
2022-09-27 12:48:41 +00:00
|
|
|
|
|
|
|
|
2022-09-27 14:01:09 +00:00
|
|
|
@main.command()
|
2022-12-18 09:00:33 +00:00
|
|
|
@click.option("--src", help="Tous les fichiers dans src", default="./")
|
2022-09-28 14:47:22 +00:00
|
|
|
@click.option("--dest", help="Où mettre les fichiers produits", default="")
|
2023-10-05 13:19:16 +00:00
|
|
|
@click.option(
|
|
|
|
"--force",
|
|
|
|
help="Ecraser si le ficher destination existe.",
|
|
|
|
default=False,
|
|
|
|
is_flag=True,
|
|
|
|
)
|
|
|
|
def join(src, dest, force):
|
|
|
|
"""Join tous les fichiers excel charge (resp locataire) de src dans un seul fichier charge.xlsx dans dist.
|
|
|
|
|
|
|
|
Exemple:
|
|
|
|
|
|
|
|
pdf-oralia join --src <dossier_source> --dest <dossier_destination>
|
|
|
|
|
|
|
|
|
|
|
|
"""
|
2023-10-05 13:10:39 +00:00
|
|
|
dest_charge = f"{dest}/charge.xlsx"
|
2023-10-05 13:19:16 +00:00
|
|
|
if not force and Path(dest_charge).exists():
|
|
|
|
raise ValueError(f"The file {dest_charge} already exists")
|
2023-10-05 13:10:39 +00:00
|
|
|
dest_locataire = f"{dest}/locataire.xlsx"
|
2023-10-05 13:19:16 +00:00
|
|
|
if not force and Path(dest_locataire).exists():
|
|
|
|
raise ValueError(f"The file {dest_locataire} already exists")
|
|
|
|
|
|
|
|
join_excel(src, dest_charge, "*_charge.xlsx")
|
|
|
|
logging.info(f"Les données charges ont été concaténées dans {dest_charge}")
|
2023-10-05 13:10:39 +00:00
|
|
|
join_excel(src, dest_locataire, "*_locataire.xlsx")
|
2023-10-05 13:19:16 +00:00
|
|
|
logging.info(f"Les données locataires ont été concaténées dans {dest_locataire}")
|