diff --git a/releve2csv b/releve2csv index 125859bb8dde047158543354510784cbc3f59e47..a5c8c139310fe4fd7034d83912bb6bce07ec7e99 100755 --- a/releve2csv +++ b/releve2csv @@ -4,6 +4,9 @@ import pandas as pd import argparse import os +################################################################################ +# ArgsParser # +################################################################################ arg_parser = argparse.ArgumentParser( description="Un simple script de convertion de relevé LCL pdf vers csv") @@ -21,27 +24,47 @@ args = arg_parser.parse_args() if args.out == "%path%.csv": args.out = os.path.splitext(args.path)[0]+'.csv' +################################################################################ +# Main # +################################################################################ print("Convertion de "+args.path+" vers "+args.out) +# Extait les tableaux présent dans le pdf en Dataframe pandas tables = camelot.read_pdf(args.path, pages="1-end", flavor="stream") -print("Total tables extracted:", tables.n) +print("Nombre de tableau extrait: ", tables.n) +# Formatage du premier tableau (la ligne de titre) +# ------------------------------------------------ first_df = tables[1].df first_df.iloc[1,1] = first_df.iloc[1,2] first_df.drop(2,inplace=True,axis=1) first_df.columns = range(first_df.columns.size) + +# Concatene tout les autres tableaux avec le premier formaté +# ---------------------------------------------------------- df_list = [first_df] if len(tables) > 2: for table in tables[2:]: df_list.append(table.df.iloc[2:]) - r = pd.concat(df_list) + +# Suppression des lignes LABELLE et REF si besoin +if not args.full_label : + r = r[r[0] != ""] + +# Formatage du tableau final +# -------------------------- +# Colonne VALEUR mise dans DATE (premiere col) r.iloc[1:,0] = r.iloc[1:,2] + +# Formatage/Insertion des collones vides pour copier/coller direct r[2] = "" r.insert(1,"","") + +# Formatage des dates r[0] = r[0].str.replace('.','/',regex=False) -if not args.full_label : - r = r[r[0] != ""] + +# Export en csv r.to_csv(args.out, sep=";",index=False, header=False)