Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -2760,8 +2760,19 @@ def _normalize_fused_date_posted_amount_table(grid):
|
|
| 2760 |
date = parts[0]
|
| 2761 |
desc = " ".join(parts[1:]).strip()
|
| 2762 |
|
| 2763 |
-
#
|
|
|
|
| 2764 |
amount = c2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2765 |
if not amount and desc:
|
| 2766 |
m = re.search(r"(-?\$?\d{1,3}(?:,\d{3})*(?:\.\d{2})-?)\s*$", desc)
|
| 2767 |
if m:
|
|
|
|
| 2760 |
date = parts[0]
|
| 2761 |
desc = " ".join(parts[1:]).strip()
|
| 2762 |
|
| 2763 |
+
# Amount may live in any shifted column for malformed OCR tables.
|
| 2764 |
+
# Prefer explicit second-column value, then rightmost strict money token in row.
|
| 2765 |
amount = c2
|
| 2766 |
+
if not amount:
|
| 2767 |
+
money_cells = []
|
| 2768 |
+
for x in cells[1:]:
|
| 2769 |
+
t = str(x or "").strip()
|
| 2770 |
+
if re.match(r"^-?\$?\d{1,3}(?:,\d{3})*(?:\.\d{2})-?$", t):
|
| 2771 |
+
money_cells.append(t)
|
| 2772 |
+
if money_cells:
|
| 2773 |
+
amount = money_cells[-1]
|
| 2774 |
+
|
| 2775 |
+
# If still empty, try extracting trailing amount from description.
|
| 2776 |
if not amount and desc:
|
| 2777 |
m = re.search(r"(-?\$?\d{1,3}(?:,\d{3})*(?:\.\d{2})-?)\s*$", desc)
|
| 2778 |
if m:
|