9 Commits

4 changed files with 76 additions and 15 deletions

View File

@@ -12,7 +12,7 @@ steps:
image: python:3.11
commands:
- echo ${DRONE_TAG}
- sed -i "s/VERSION_PLACEHOLDER/${DRONE_TAG}/g" pyproject.toml
- sed -i 's/version = "[^"]*"/version = "${DRONE_TAG}"/g' pyproject.toml
- curl -sSL https://install.python-poetry.org | python3 -
- export PATH="/root/.local/bin:$PATH"
- poetry --version
@@ -22,6 +22,19 @@ steps:
PYPI_TOKEN:
from_secret: pypi_token
- name: Notify on matrix
image: plugins/matrix
environment:
MATRIX_ROOMID:
from_secret: MATRIX_ROOMID
MATRIX_ACCESSTOKEN:
from_secret: MATRIX_ACCESSTOKEN
MATRIX_USERID:
from_secret: MATRIX_USERID
settings:
homeserver: https://matrix.poneyworld.net
template: "Une nouvelle version (${DRONE_TAG}) de pdf-oralia est publiée!"
when:
event:
include:

View File

@@ -3,7 +3,21 @@ import re
import numpy as np
import pandas as pd
RECAPITULATIF_DES_OPERATION = 1
RECAPITULATIF_DES_OPERATIONS = 1
DF_TYPES = {
"Fournisseur": str,
"RECAPITULATIF DES OPERATIONS": str,
"Débits": float,
"Crédits": float,
"Dont T.V.A.": float,
"Locatif": float,
"Déductible": float,
"immeuble": str,
"mois": str,
"annee": str,
"lot": str,
}
DEFAULT_FOURNISSEUR = "ROSIER MODICA MOTTEROZ SA"
def is_it(page_text):
@@ -17,7 +31,7 @@ def is_it(page_text):
def get_lot(txt):
"""Return lot number from "RECAPITULATIF DES OPERATIONS" """
regex = r"[BSM](\d+)\s-"
regex = r"[BSM](\d+)(?=\s*-)"
result = re.findall(regex, txt)
if result:
return "{:02d}".format(int(result[0]))
@@ -27,14 +41,14 @@ def get_lot(txt):
def keep_row(row):
return not any(
[
word.lower() in row[RECAPITULATIF_DES_OPERATION].lower()
word.lower() in row[RECAPITULATIF_DES_OPERATIONS].lower()
for word in ["TOTAL", "TOTAUX", "Solde créditeur", "Solde débiteur"]
]
)
def extract(table, additionnal_fields: dict = {}):
"""Turn table to dictionary with additionnal fields"""
"""Turn table to dictionary with additional fields"""
extracted = []
header = table[0]
for row in table[1:]:
@@ -49,10 +63,8 @@ def extract(table, additionnal_fields: dict = {}):
for k, v in additionnal_fields.items():
r[k] = v
r["lot"] = get_lot(row[RECAPITULATIF_DES_OPERATION])
if "honoraire" in row[RECAPITULATIF_DES_OPERATION]:
r["Fournisseur"] = "IMI GERANCE"
if "honoraire" in row[RECAPITULATIF_DES_OPERATIONS].lower():
r["Fournisseur"] = DEFAULT_FOURNISSEUR
extracted.append(r)
@@ -69,4 +81,8 @@ def table2df(tables):
)
df["Fournisseur"] = df["Fournisseur"].fillna(method="ffill")
dfs.append(df)
return pd.concat(dfs)
df = pd.concat(dfs)
df["immeuble"] = df["immeuble"].apply(lambda x: x[0].capitalize())
df["lot"] = df["RECAPITULATIF DES OPERATIONS"].apply(get_lot)
return df.astype(DF_TYPES)

View File

@@ -1,5 +1,23 @@
import numpy as np
import pandas as pd
DF_TYPES = {
"Locataires": str,
"Période": str,
"Loyers": float,
"Taxes": float,
"Provisions": float,
"Divers": str,
"Total": float,
"Réglés": float,
"Impayés": float,
"immeuble": str,
"mois": str,
"annee": str,
"Lot": str,
"Type": str,
}
def is_it(page_text):
if "SITUATION DES LOCATAIRES" in page_text:
@@ -16,7 +34,7 @@ def is_drop(row):
def extract(table, additionnal_fields: dict = {}):
"""Turn table to dictionary with additionnal fields"""
"""Turn table to dictionary with additional fields"""
extracted = []
header = table[0]
for row in table[1:]:
@@ -67,6 +85,12 @@ def parse_lot(string):
return {"Lot": "{:02d}".format(int(words[1])), "Type": " ".join(words[2:])}
def clean_type(string):
if "appartement" in string.lower():
return string[-2:]
return string
def join_row(table):
joined = []
for row in table:
@@ -115,8 +139,6 @@ def join_row(table):
}
)
joined.append(row)
else:
print(row)
return joined
@@ -131,4 +153,14 @@ def flat_tables(tables):
def table2df(tables):
tables = flat_tables(tables)
joined = join_row(tables)
return pd.DataFrame.from_records(joined)
df = pd.DataFrame.from_records(joined)
df["immeuble"] = df["immeuble"].apply(lambda x: x[0].capitalize())
df["Type"] = df["Type"].apply(clean_type)
numeric_cols = [k for k, v in DF_TYPES.items() if v == float]
df[numeric_cols] = df[numeric_cols].replace("", np.nan)
df = df.drop(df[(df["Locataires"] == "") & (df["Période"] == "")].index)
return df.astype(DF_TYPES)

View File

@@ -1,6 +1,6 @@
[tool.poetry]
name = "pdf-oralia"
version = "VERSION_PLACEHOLDER"
version = "dev"
description = ""
authors = ["Bertrand Benjamin <benjamin.bertrand@opytex.org>"]
readme = "README.md"