From e288d4f2ddf2a2a6cecefdc76deb253ccaea60d9 Mon Sep 17 00:00:00 2001 From: laurentbarontini Date: Sun, 11 Jan 2026 18:16:55 +0100 Subject: [PATCH] 11.01.26 --- app.py | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/app.py b/app.py index e57a5d4..da09da0 100644 --- a/app.py +++ b/app.py @@ -136,13 +136,16 @@ class AHKParser: def _lines(self, text): return [l.strip() for l in text.splitlines() if l.strip()] - def _col_block(self, lines, labels, max_scan=25): - # trouve la dernière ligne du bloc de labels - last = max(i for i,l in enumerate(lines) if l in labels) + def _col_block(self, lines, labels, max_scan=30): + idx = [i for i,l in enumerate(lines) if l in labels] + if not idx: + return {} # << empêche le crash + start = max(idx) + 1 vals = [] - for l in lines[last+1:last+1+max_scan]: + for l in lines[start:start+max_scan]: if l.startswith(":"): - vals.append(l[1:].strip()) + v = l[1:].replace("kg","").strip() + vals.append(v) if len(vals) == len(labels): break return dict(zip(labels, vals)) @@ -186,8 +189,10 @@ class AHKParser: r["weights"]["invoice_net_kg"] = to_float(inv.get("Net")) # landed weights - land = self._col_block(self._lines(section(text,"Bales Weighed","Outturn")), - ["Bales","Gross","Tare","Net"]) + land = self._col_block( + self._lines(section(text,"Bales Weighed","Outturn")), + ["Bales","Gross","Tare","Net"] + ) r["weights"]["gross_landed_kg"] = to_float(land.get("Gross")) r["weights"]["tare_kg"] = to_float(land.get("Tare"))