Add HSBC bank statement parser with common OCR support
This commit is contained in:
@@ -3,6 +3,7 @@ from __future__ import annotations
|
||||
from .idfc import IDFCFirstParser
|
||||
from .axis import AxisParser
|
||||
from .hdfc import HDFCParser
|
||||
from .hsbc import HSBCParser
|
||||
from .indian_bank import IndianBankModernParser, IndianBankLegacyParser
|
||||
from .indusind import IndusIndParser
|
||||
from .kotak import KotakParser
|
||||
@@ -13,6 +14,7 @@ PARSERS = [
|
||||
IDFCFirstParser,
|
||||
AxisParser,
|
||||
HDFCParser,
|
||||
HSBCParser,
|
||||
IndianBankModernParser,
|
||||
IndianBankLegacyParser,
|
||||
IndusIndParser,
|
||||
@@ -25,6 +27,7 @@ BANK_OPTIONS = [
|
||||
("auto", "Auto Detect"),
|
||||
("axis", "Axis Bank"),
|
||||
("hdfc", "HDFC Bank"),
|
||||
("hsbc", "HSBC Bank"),
|
||||
("idfc", "IDFC FIRST Bank"),
|
||||
("indian_bank", "Indian Bank"),
|
||||
("indusind", "IndusInd Bank"),
|
||||
@@ -35,6 +38,7 @@ BANK_OPTIONS = [
|
||||
BANK_PARSERS = {
|
||||
"axis": [AxisParser],
|
||||
"hdfc": [HDFCParser],
|
||||
"hsbc": [HSBCParser],
|
||||
"idfc": [IDFCFirstParser],
|
||||
"indian_bank": [IndianBankModernParser, IndianBankLegacyParser],
|
||||
"indusind": [IndusIndParser],
|
||||
@@ -61,8 +65,10 @@ def _selected_parser(bank_key: str, text: str):
|
||||
|
||||
|
||||
def parse_pdf(path, bank_hint: str | None = None):
|
||||
text = extract_text(path)
|
||||
hint = (bank_hint or "auto").strip().lower()
|
||||
if hint == "hsbc":
|
||||
return HSBCParser().parse(path, "")
|
||||
text = extract_text(path)
|
||||
if hint and hint != "auto":
|
||||
parser, score = _selected_parser(hint, text)
|
||||
if parser is None:
|
||||
@@ -73,6 +79,13 @@ def parse_pdf(path, bank_hint: str | None = None):
|
||||
)
|
||||
return parser.parse(path, text)
|
||||
parser, score = detect_parser(text)
|
||||
if parser is None and not (text or "").strip():
|
||||
# Image-only statements cannot be identified by pdftotext. HSBCParser
|
||||
# performs its own OCR identification and raises a precise mismatch error.
|
||||
try:
|
||||
return HSBCParser().parse(path, text)
|
||||
except ValueError:
|
||||
pass
|
||||
if parser is None:
|
||||
raise ValueError(
|
||||
"Unsupported statement format. Select the bank manually or add a bank-specific parser for this statement layout."
|
||||
|
||||
Reference in New Issue
Block a user