11.01.26
This commit is contained in:
19
app.py
19
app.py
@@ -136,13 +136,16 @@ class AHKParser:
|
|||||||
def _lines(self, text):
|
def _lines(self, text):
|
||||||
return [l.strip() for l in text.splitlines() if l.strip()]
|
return [l.strip() for l in text.splitlines() if l.strip()]
|
||||||
|
|
||||||
def _col_block(self, lines, labels, max_scan=25):
|
def _col_block(self, lines, labels, max_scan=30):
|
||||||
# trouve la dernière ligne du bloc de labels
|
idx = [i for i,l in enumerate(lines) if l in labels]
|
||||||
last = max(i for i,l in enumerate(lines) if l in labels)
|
if not idx:
|
||||||
|
return {} # << empêche le crash
|
||||||
|
start = max(idx) + 1
|
||||||
vals = []
|
vals = []
|
||||||
for l in lines[last+1:last+1+max_scan]:
|
for l in lines[start:start+max_scan]:
|
||||||
if l.startswith(":"):
|
if l.startswith(":"):
|
||||||
vals.append(l[1:].strip())
|
v = l[1:].replace("kg","").strip()
|
||||||
|
vals.append(v)
|
||||||
if len(vals) == len(labels):
|
if len(vals) == len(labels):
|
||||||
break
|
break
|
||||||
return dict(zip(labels, vals))
|
return dict(zip(labels, vals))
|
||||||
@@ -186,8 +189,10 @@ class AHKParser:
|
|||||||
r["weights"]["invoice_net_kg"] = to_float(inv.get("Net"))
|
r["weights"]["invoice_net_kg"] = to_float(inv.get("Net"))
|
||||||
|
|
||||||
# landed weights
|
# landed weights
|
||||||
land = self._col_block(self._lines(section(text,"Bales Weighed","Outturn")),
|
land = self._col_block(
|
||||||
["Bales","Gross","Tare","Net"])
|
self._lines(section(text,"Bales Weighed","Outturn")),
|
||||||
|
["Bales","Gross","Tare","Net"]
|
||||||
|
)
|
||||||
|
|
||||||
r["weights"]["gross_landed_kg"] = to_float(land.get("Gross"))
|
r["weights"]["gross_landed_kg"] = to_float(land.get("Gross"))
|
||||||
r["weights"]["tare_kg"] = to_float(land.get("Tare"))
|
r["weights"]["tare_kg"] = to_float(land.get("Tare"))
|
||||||
|
|||||||
Reference in New Issue
Block a user