Skip to content

Commit

Permalink
feat(banks): add support for chase credit
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-awd committed Nov 15, 2024
1 parent ffbda60 commit aa24c4f
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 2 deletions.
2 changes: 2 additions & 0 deletions src/monopoly/banks/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from typing import Type

from .base import BankBase
from .chase import Chase
from .citibank import Citibank
from .dbs import Dbs
from .detector import BankDetector
Expand All @@ -14,6 +15,7 @@
from .zkb import ZurcherKantonalBank

banks: list[Type["BankBase"]] = [
Chase,
Citibank,
Dbs,
ExampleBank,
Expand Down
3 changes: 3 additions & 0 deletions src/monopoly/banks/chase/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
from .chase import Chase

__all__ = ["Chase"]
36 changes: 36 additions & 0 deletions src/monopoly/banks/chase/chase.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import logging
from re import compile as regex

from monopoly.config import DateOrder, StatementConfig
from monopoly.constants import BankNames, CreditTransactionPatterns, EntryType
from monopoly.identifiers import MetadataIdentifier, TextIdentifier

from ..base import BankBase

logger = logging.getLogger(__name__)


class Chase(BankBase):
name = BankNames.CHASE

credit = StatementConfig(
statement_type=EntryType.CREDIT,
statement_date_pattern=regex(r"Statement Date:\s+(.*)"),
statement_date_order=DateOrder("MDY"),
transaction_date_order=DateOrder("MDY"),
header_pattern=regex(r"(.*Transaction.*Merchant Name .*\$ Amount)"),
transaction_pattern=CreditTransactionPatterns.CHASE,
multiline_transactions=True,
)

identifiers = [
[
MetadataIdentifier(
format="PDF 1.7",
producer="OpenText Output Transformation Engine - 23.4",
),
TextIdentifier("Chase"),
]
]

statement_configs = [credit]
1 change: 1 addition & 0 deletions src/monopoly/constants/date.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ class ISO8601(RegexEnum):
DD_MMM_YYYY = (
rf"\b({DateFormats.DD}[-\s]{DateFormats.MMM}[,\s]{{1,2}}{DateFormats.YYYY})"
)
MM_DD = rf"\b({DateFormats.MM}[\/\-\s]{DateFormats.DD})"
MMMM_DD_YYYY = (
rf"\b({DateFormats.MMMM}\s{DateFormats.DD}[,\s]{{1,2}}{DateFormats.YYYY})"
)
Expand Down
10 changes: 10 additions & 0 deletions src/monopoly/constants/statement.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ class EntryType(AutoEnum):


class BankNames(AutoEnum):
CHASE = auto()
CITIBANK = auto()
DBS = auto()
HSBC = auto()
Expand Down Expand Up @@ -71,6 +72,10 @@ class StatementBalancePatterns(RegexEnum):
r"(?P<description>PREVIOUS BALANCE?)\s+"
+ SharedPatterns.AMOUNT_EXTENDED_WITHOUT_EOL
)
CHASE = (
r"(?P<description>BALANCE PREVIOUS STATEMENT?)\s+"
+ SharedPatterns.AMOUNT_EXTENDED_WITHOUT_EOL
)
CITIBANK = (
r"(?P<description>BALANCE PREVIOUS STATEMENT?)\s+"
+ SharedPatterns.AMOUNT_EXTENDED_WITHOUT_EOL
Expand Down Expand Up @@ -103,6 +108,11 @@ class CreditTransactionPatterns(RegexEnum):
+ SharedPatterns.DESCRIPTION
+ SharedPatterns.AMOUNT_EXTENDED
)
CHASE = (
rf"(?P<transaction_date>{ISO8601.MM_DD})\s+"
+ SharedPatterns.DESCRIPTION
+ SharedPatterns.AMOUNT_EXTENDED
)
CITIBANK = (
rf"(?P<transaction_date>{ISO8601.DD_MMM})\s+"
+ SharedPatterns.DESCRIPTION
Expand Down
3 changes: 1 addition & 2 deletions src/monopoly/statements/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,8 +204,7 @@ def statement_date(self) -> datetime:
)
if statement_date:
return statement_date
else:
logger.info("Unable to parse statement date %s", match.group(1))
logger.info("Unable to parse statement date %s", match.group(1))
raise ValueError("Statement date not found")

def get_decimal_numbers(self, lines: list[str]) -> set[float]:
Expand Down

0 comments on commit aa24c4f

Please sign in to comment.