Skip to content

Commit

Permalink
refactor(examples): use non-bank specific example
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamin-awd committed Oct 8, 2023
1 parent 814526d commit f094d8d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 6 deletions.
Binary file added monopoly/examples/example_statement.pdf
Binary file not shown.
Binary file removed monopoly/examples/ocbc_365_example.pdf
Binary file not shown.
31 changes: 25 additions & 6 deletions monopoly/examples/single_statement.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,31 @@
from monopoly.banks.ocbc import Ocbc
from monopoly.bank import BankBase
from monopoly.helpers.constants import AccountType, BankNames
from monopoly.statement import StatementConfig


def ocbc_example():
# fmt: off
class MonopolyBank(BankBase):
"""Dummy class to help with reading the example PDF statement"""
statement_config = StatementConfig(
bank_name=BankNames.EXAMPLE,
account_type=AccountType.CREDIT,
transaction_pattern=(
r"(?P<date>\d+/\d+)\s*"
r"(?P<description>.*?)\s*"
r"(?P<amount>[\d.,]+)$"
),
transaction_date_format=r"%d/%m",
statement_date_pattern=r"\d{2}\-\d{2}\-\d{4}",
statement_date_format=r"%d-%m-%Y",
)


def example():
"""Example showing how monopoly can be used to extract data from
a single bank statement
"""
bank = Ocbc(
file_path="monopoly/examples/ocbc_365_example.pdf",
bank = MonopolyBank(
file_path="monopoly/examples/example_statement.pdf",
)

# This runs Tesseract on the PDF and
Expand All @@ -18,9 +37,9 @@ def ocbc_example():
print(transformed_df)

# Files are saved to an output directory
# monopoly/output/OCBC-Credit-2023-08.csv
# monopoly/output/monopoly-credit-2023-08.csv
bank.load(transformed_df, statement)


if __name__ == "__main__":
ocbc_example()
example()
1 change: 1 addition & 0 deletions monopoly/helpers/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ class BankNames(Enum):
CITIBANK = "citibank"
HSBC = "hsbc"
OCBC = "ocbc"
EXAMPLE = "monopoly"


class BankStatement(str, Enum):
Expand Down

0 comments on commit f094d8d

Please sign in to comment.