Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pdfparser/pdfoxide_parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ def parse_pdf_pdfoxide(path: str) -> Dict[str, Any]:
# Extract transactions from all pages
all_text = ""
for page_num in range(page_count):
page_text = doc.extract_text(page_num) # type: ignore[attr-defined] or ""
page_text = doc.extract_text(page_num) or "" # type: ignore[attr-defined]
all_text += page_text + "\n"
transactions = extract_transactions(all_text)

Expand Down
3 changes: 2 additions & 1 deletion pdfparser/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@
_WHITESPACE_PATTERN: Pattern = re.compile(r"\s+")
_NUMERIC_LINE_PATTERN: Pattern = re.compile(r"^[\d,.]+\s*$")
_NUMERIC_ONLY_PATTERN: Pattern = re.compile(r"^[\d,.]*$")
_AMOUNT_PATTERN: Pattern = re.compile(r"^[\d,]+\.\d{2}$")
# Support both US (1,234.56) and Indonesian (1.234,56) formats
_AMOUNT_PATTERN: Pattern = re.compile(r"^(?:[\d,]+\.\d{2}|[\d.]+\,\d{2})$")
_USER_ID_PATTERN: Pattern = re.compile(r"^\d{6,8}$")

# Summary section label patterns (compiled for extract_summary_totals)
Expand Down
39 changes: 39 additions & 0 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,45 @@ def test_extract_transactions_keys_are_strings(self, transaction_text):
for key in item.keys():
assert isinstance(key, str), f"Key '{key}' is not a string"

def test_extract_transactions_indonesian_format(self):
"""Verify extraction of Indonesian number format (comma decimal)."""
text = """
01/01/23 12:00:00
TRANSFER IN
1.000.000,00
0,00
10.000.000,00
"""
transactions = extract_transactions(text)

assert len(transactions) == 1
txn = transactions[0]

# Verify parsing
assert txn["debit"] == "1.000.000,00"
assert txn["credit"] == "0,00"
assert txn["balance"] == "10.000.000,00"
assert txn["user"] == ""

def test_extract_transactions_us_format(self):
"""Verify extraction of US number format (dot decimal)."""
text = """
01/01/23 12:00:00
TRANSFER IN
1,000,000.00
0.00
10,000,000.00
"""
transactions = extract_transactions(text)

assert len(transactions) == 1
txn = transactions[0]

assert txn["debit"] == "1,000,000.00"
assert txn["credit"] == "0.00"
assert txn["balance"] == "10,000,000.00"
assert txn["user"] == ""


class TestTransactionDatePattern:
"""Tests for transaction date regex pattern using hypothesis."""
Expand Down
Loading