feat: PDF-Parser VR/HVB/DKB mit Registry und Fixture-Tests
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
21
finance/app/parsers/registry.py
Normal file
21
finance/app/parsers/registry.py
Normal file
@@ -0,0 +1,21 @@
|
||||
from pathlib import Path
|
||||
from typing import Callable
|
||||
|
||||
import pdfplumber
|
||||
|
||||
from app.parsers import dkb, hvb, vr
|
||||
from app.parsers.base import ParsedStatement, ParserError
|
||||
from app.parsers.detect import detect_bank
|
||||
|
||||
PARSERS: dict[str, Callable[[Path], ParsedStatement]] = {
|
||||
"vr": vr.parse, "hvb": hvb.parse, "dkb": dkb.parse,
|
||||
}
|
||||
|
||||
|
||||
def parse_pdf(path: Path) -> ParsedStatement:
|
||||
with pdfplumber.open(path) as pdf:
|
||||
first = pdf.pages[0].extract_text() or ""
|
||||
bank = detect_bank(first)
|
||||
if bank is None:
|
||||
raise ParserError("Bank nicht erkannt")
|
||||
return PARSERS[bank](path)
|
||||
Reference in New Issue
Block a user