Compare commits
18 Commits
v0.3.6
...
0fc39ed317
| Author | SHA1 | Date | |
|---|---|---|---|
| 0fc39ed317 | |||
| a6d6681756 | |||
| 4eecb3a44c | |||
| 60da623323 | |||
| 1f1e3e2741 | |||
| 2b3e935f39 | |||
| ef63f22d44 | |||
| 1020ef9257 | |||
| 39084ceebd | |||
| 7de6c8dd9c | |||
| da3815eea6 | |||
| 45d343d810 | |||
| 806227f202 | |||
| 7bf0c38883 | |||
| b15b059e2a | |||
| 48e75358ac | |||
| 132e37267b | |||
| f2bcf6241a |
29
pdf_oralia/join.py
Normal file
29
pdf_oralia/join.py
Normal file
@@ -0,0 +1,29 @@
|
|||||||
|
import glob
|
||||||
|
import logging
|
||||||
|
|
||||||
|
import pandas as pd
|
||||||
|
|
||||||
|
|
||||||
|
def join_excel(src, dest, file_pattern):
|
||||||
|
"""Join every excel file in arc respecting file_pattern into on unique file in dist"""
|
||||||
|
filenames = list_files(src, file_pattern)
|
||||||
|
logging.debug(f"Concatenate {filenames}")
|
||||||
|
dfs = extract_dfs(filenames)
|
||||||
|
joined_df = pd.concat(dfs)
|
||||||
|
logging.debug(f"Writing joined excel to {dest}")
|
||||||
|
joined_df.to_excel(dest, index=False)
|
||||||
|
logging.debug(f"with {len(joined_df)} rows")
|
||||||
|
|
||||||
|
|
||||||
|
def list_files(src, file_glob):
|
||||||
|
return list(glob.iglob(f"{src}/{file_glob}"))
|
||||||
|
|
||||||
|
|
||||||
|
def extract_dfs(filenames):
|
||||||
|
dfs = []
|
||||||
|
for filename in filenames:
|
||||||
|
logging.debug(f"Extracting {filename}")
|
||||||
|
df = pd.read_excel(filename)
|
||||||
|
logging.debug(f"Found {len(df)} rows")
|
||||||
|
dfs.append(df)
|
||||||
|
return dfs
|
||||||
@@ -5,29 +5,33 @@ from pathlib import Path
|
|||||||
import click
|
import click
|
||||||
|
|
||||||
from .extract import extract_save
|
from .extract import extract_save
|
||||||
|
from .join import join_excel
|
||||||
|
|
||||||
logging_config = dict(
|
|
||||||
|
@click.group()
|
||||||
|
@click.option("--debug/--no-debug", default=False)
|
||||||
|
def main(debug):
|
||||||
|
if debug:
|
||||||
|
logging_level = logging.DEBUG
|
||||||
|
else:
|
||||||
|
logging_level = logging.INFO
|
||||||
|
logging_config = dict(
|
||||||
version=1,
|
version=1,
|
||||||
formatters={"f": {"format": "%(levelname)-8s %(name)-12s %(message)s"}},
|
formatters={"f": {"format": "%(levelname)-8s %(name)-12s %(message)s"}},
|
||||||
handlers={
|
handlers={
|
||||||
"h": {
|
"h": {
|
||||||
"class": "logging.StreamHandler",
|
"class": "logging.StreamHandler",
|
||||||
"formatter": "f",
|
"formatter": "f",
|
||||||
"level": logging.DEBUG,
|
"level": logging_level,
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
root={
|
root={
|
||||||
"handlers": ["h"],
|
"handlers": ["h"],
|
||||||
"level": logging.DEBUG,
|
"level": logging_level,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
|
|
||||||
dictConfig(logging_config)
|
dictConfig(logging_config)
|
||||||
|
|
||||||
|
|
||||||
@click.group()
|
|
||||||
def main():
|
|
||||||
pass
|
|
||||||
|
|
||||||
|
|
||||||
@main.group()
|
@main.group()
|
||||||
@@ -64,5 +68,31 @@ def all(src, dest):
|
|||||||
@main.command()
|
@main.command()
|
||||||
@click.option("--src", help="Tous les fichiers dans src", default="./")
|
@click.option("--src", help="Tous les fichiers dans src", default="./")
|
||||||
@click.option("--dest", help="Où mettre les fichiers produits", default="")
|
@click.option("--dest", help="Où mettre les fichiers produits", default="")
|
||||||
def join(src, dest):
|
@click.option(
|
||||||
join_excel(src, dest, df_names=["charge", "locataire"])
|
"--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>
|
||||||
|
|
||||||
|
|
||||||
|
"""
|
||||||
|
dest_charge = f"{dest}/charge.xlsx"
|
||||||
|
if not force and Path(dest_charge).exists():
|
||||||
|
raise ValueError(f"The file {dest_charge} already exists")
|
||||||
|
dest_locataire = f"{dest}/locataire.xlsx"
|
||||||
|
if not force and Path(dest_locataire).exists():
|
||||||
|
raise ValueError(f"The file {dest_locataire} already exists")
|
||||||
|
|
||||||
|
if not Path(src).exists():
|
||||||
|
raise ValueError(f"The source directory ({src}) does not exists.")
|
||||||
|
join_excel(src, dest_charge, "*_charge.xlsx")
|
||||||
|
logging.info(f"Les données charges ont été concaténées dans {dest_charge}")
|
||||||
|
join_excel(src, dest_locataire, "*_locataire.xlsx")
|
||||||
|
logging.info(f"Les données locataires ont été concaténées dans {dest_locataire}")
|
||||||
|
|||||||
2
renovate.json
Normal file
2
renovate.json
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
{
|
||||||
|
}
|
||||||
@@ -20,7 +20,7 @@ ipython==8.5.0
|
|||||||
ipython-genutils==0.2.0
|
ipython-genutils==0.2.0
|
||||||
ipywidgets==8.0.2
|
ipywidgets==8.0.2
|
||||||
jedi==0.18.1
|
jedi==0.18.1
|
||||||
Jinja2==3.1.2
|
Jinja2==3.1.3
|
||||||
jsonschema==4.16.0
|
jsonschema==4.16.0
|
||||||
jupyter==1.0.0
|
jupyter==1.0.0
|
||||||
jupyter-console==6.4.4
|
jupyter-console==6.4.4
|
||||||
@@ -29,7 +29,7 @@ jupyter_client==7.3.5
|
|||||||
jupyterlab-pygments==0.2.2
|
jupyterlab-pygments==0.2.2
|
||||||
jupyterlab-widgets==3.0.3
|
jupyterlab-widgets==3.0.3
|
||||||
lxml==4.9.1
|
lxml==4.9.1
|
||||||
MarkupSafe==2.1.1
|
MarkupSafe==2.1.5
|
||||||
matplotlib-inline==0.1.6
|
matplotlib-inline==0.1.6
|
||||||
mistune==2.0.4
|
mistune==2.0.4
|
||||||
nbclient==0.6.8
|
nbclient==0.6.8
|
||||||
@@ -62,7 +62,7 @@ pytz==2022.2.1
|
|||||||
pyzmq==24.0.1
|
pyzmq==24.0.1
|
||||||
qtconsole==5.3.2
|
qtconsole==5.3.2
|
||||||
QtPy==2.2.0
|
QtPy==2.2.0
|
||||||
Send2Trash==1.8.0
|
Send2Trash==1.8.2
|
||||||
six==1.16.0
|
six==1.16.0
|
||||||
soupsieve==2.3.2.post1
|
soupsieve==2.3.2.post1
|
||||||
stack-data==0.5.1
|
stack-data==0.5.1
|
||||||
|
|||||||
Reference in New Issue
Block a user