11.01.26
This commit is contained in:
19
app.py
19
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"))
|
||||
|
||||
Reference in New Issue
Block a user