Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(examples): use fictional bank example #17

Merged
merged 2 commits into from
Oct 8, 2023
Merged
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
3 changes: 2 additions & 1 deletion monopoly/bank.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import os
from dataclasses import dataclass
from datetime import datetime
from typing import Optional

from google.cloud import storage
from pandas import DataFrame
Expand All @@ -17,9 +18,9 @@

@dataclass
class Bank:
pdf_config: PdfConfig
statement_config: StatementConfig
file_path: str
pdf_config: Optional[PdfConfig] = None
transform_dates: bool = True

def extract(self) -> Statement:
Expand Down
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