-
Notifications
You must be signed in to change notification settings - Fork 3
feat: bank transactions with a Plaid like schema #253
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
Open
Eeshita-Pande
wants to merge
11
commits into
main
Choose a base branch
from
claude/bank-transactions-DAfeN
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
ca1827d
test files for remote Claude
Eeshita-Pande 8f1a863
feat: add bank transactions provider with Revolut, Amex, and Barclays…
claude c0d1d8a
fix: resolve ruff SIM108 and E501 lint errors in bank providers
claude 609160e
style: apply ruff format to revolut pipe
claude 1a9847e
fix: address audit findings for bank transaction providers
claude 3edd6f0
refactor: promote bank institutions to top-level providers with per-r…
claude 8ddd8dd
feat: add generic bank CSV provider with interactive column mapping
claude 57a3f30
Merge branch 'main' into claude/bank-transactions-DAfeN
Eeshita-Pande 9678460
style: fix import sorting and line length violations
claude 22b2660
fix: restore Pipe import lost during rebase
claude c2403dd
style: apply ruff format to test_generic.py
claude File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,192 @@ | ||
| """Interactive column-mapping setup for the generic bank provider. | ||
|
|
||
| Reads CSV headers from a zip archive and walks the user through mapping | ||
| columns to the fields required by :class:`BankMapping`. | ||
| """ | ||
|
|
||
| from __future__ import annotations | ||
|
|
||
| import csv | ||
| import io | ||
| import zipfile | ||
|
|
||
| from context_use.cli import output as out | ||
| from context_use.providers.bank.mapping import AmountColumns, BankMapping | ||
|
|
||
|
|
||
| def _read_csv_headers(zip_path: str) -> tuple[str, list[str]] | None: | ||
| """Extract headers from the first CSV found inside *zip_path*. | ||
|
|
||
| Returns ``(csv_filename, headers)`` or ``None`` if no CSV is found. | ||
| """ | ||
| with zipfile.ZipFile(zip_path) as zf: | ||
| for name in sorted(zf.namelist()): | ||
| if name.startswith("__MACOSX"): | ||
| continue | ||
| if name.lower().endswith(".csv"): | ||
| with zf.open(name) as f: | ||
| reader = csv.reader(io.TextIOWrapper(f, encoding="utf-8")) | ||
| try: | ||
| headers = next(reader) | ||
| except StopIteration: | ||
| continue | ||
| return name, [h.strip() for h in headers] | ||
| return None | ||
|
|
||
|
|
||
| def _pick_column(headers: list[str], prompt_text: str) -> str | None: | ||
| """Let the user pick one column by number.""" | ||
| choice = input(prompt_text).strip() | ||
| try: | ||
| idx = int(choice) - 1 | ||
| if 0 <= idx < len(headers): | ||
| return headers[idx] | ||
| except ValueError: | ||
| pass | ||
| out.error("Invalid choice.") | ||
| return None | ||
|
|
||
|
|
||
| def _print_columns(headers: list[str]) -> None: | ||
| for i, h in enumerate(headers, 1): | ||
| print(f" {out.bold(str(i))}. {h}") | ||
| print() | ||
|
|
||
|
|
||
| def _ask_amount_columns(headers: list[str]) -> AmountColumns | None: | ||
| """Ask whether amount is a single column or split into in/out.""" | ||
| out.header("Amount columns") | ||
| print() | ||
| print(f" {out.bold('1')}. Single column (e.g. +100 / -50)") | ||
| print(f" {out.bold('2')}. Separate columns for money in / money out") | ||
| print() | ||
|
|
||
| mode = input(" Amount format? [1-2]: ").strip() | ||
|
|
||
| if mode == "1": | ||
| print() | ||
| out.info("Which column contains the transaction amount?") | ||
| print() | ||
| _print_columns(headers) | ||
| col = _pick_column(headers, f" Amount column [1-{len(headers)}]: ") | ||
| if col is None: | ||
| return None | ||
| return AmountColumns(single=col) | ||
|
|
||
| if mode == "2": | ||
| print() | ||
| out.info("Which column contains money IN (credits/deposits)?") | ||
| print() | ||
| _print_columns(headers) | ||
| col_in = _pick_column(headers, f" Money-in column [1-{len(headers)}]: ") | ||
| if col_in is None: | ||
| return None | ||
|
|
||
| print() | ||
| out.info("Which column contains money OUT (debits/payments)?") | ||
| print() | ||
| _print_columns(headers) | ||
| col_out = _pick_column(headers, f" Money-out column [1-{len(headers)}]: ") | ||
| if col_out is None: | ||
| return None | ||
|
|
||
| return AmountColumns(money_in=col_in, money_out=col_out) | ||
|
|
||
| out.error("Invalid choice.") | ||
| return None | ||
|
|
||
|
|
||
| def _ask_yes_no(prompt_text: str, *, default: bool = False) -> bool: | ||
| hint = "Y/n" if default else "y/N" | ||
| answer = input(f" {prompt_text} [{hint}]: ").strip().lower() | ||
| if not answer: | ||
| return default | ||
| return answer in ("y", "yes") | ||
|
|
||
|
|
||
| def run_bank_setup(zip_path: str) -> BankMapping | None: | ||
| """Run the full interactive bank CSV setup. | ||
|
|
||
| Returns a :class:`BankMapping` or ``None`` if the user aborts. | ||
| """ | ||
| result = _read_csv_headers(zip_path) | ||
| if result is None: | ||
| out.error("No CSV files found in the archive.") | ||
| return None | ||
|
|
||
| csv_filename, headers = result | ||
| if not headers: | ||
| out.error(f"CSV file {csv_filename} has no columns.") | ||
| return None | ||
|
|
||
| out.header("Bank CSV setup") | ||
| out.kv("File", csv_filename) | ||
| print() | ||
|
|
||
| out.info("CSV columns found:") | ||
| print() | ||
| _print_columns(headers) | ||
|
|
||
| bank_name = input(" Bank name (e.g. Chase, HSBC): ").strip() | ||
| if not bank_name: | ||
| out.error("Bank name is required.") | ||
| return None | ||
|
|
||
| print() | ||
| out.info("Which column contains the transaction date?") | ||
| print() | ||
| _print_columns(headers) | ||
| date_col = _pick_column(headers, f" Date column [1-{len(headers)}]: ") | ||
| if date_col is None: | ||
| return None | ||
|
|
||
| print() | ||
| amount = _ask_amount_columns(headers) | ||
| if amount is None: | ||
| return None | ||
|
|
||
| print() | ||
| out.info("Which column contains the transaction description?") | ||
| print() | ||
| _print_columns(headers) | ||
| desc_col = _pick_column(headers, f" Description column [1-{len(headers)}]: ") | ||
| if desc_col is None: | ||
| return None | ||
|
|
||
| print() | ||
| is_credit_card = _ask_yes_no( | ||
| "Is this a credit card? (charges shown as positive amounts)" | ||
| ) | ||
|
|
||
| print() | ||
| currency = input(" Currency code (e.g. GBP, USD, EUR): ").strip().upper() | ||
| if not currency: | ||
| out.error("Currency is required.") | ||
| return None | ||
|
|
||
| print() | ||
| out.header("Mapping summary") | ||
| out.kv("Bank", bank_name) | ||
| out.kv("Date column", date_col) | ||
| if amount.single: | ||
| out.kv("Amount column", amount.single) | ||
| else: | ||
| out.kv("Money-in column", amount.money_in) | ||
| out.kv("Money-out column", amount.money_out) | ||
| out.kv("Description column", desc_col) | ||
| out.kv("Credit card", "yes" if is_credit_card else "no") | ||
| out.kv("Currency", currency) | ||
| print() | ||
|
|
||
| if not _ask_yes_no("Proceed with this mapping?", default=True): | ||
| out.warn("Aborted.") | ||
| return None | ||
|
|
||
| return BankMapping( | ||
| bank_name=bank_name, | ||
| date_column=date_col, | ||
| amount=amount, | ||
| description_column=desc_col, | ||
| currency=currency, | ||
| is_credit_card=is_credit_card, | ||
| ) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| from context_use.providers.amex import transactions | ||
| from context_use.providers.registry import register_provider | ||
|
|
||
| PROVIDER = "amex" | ||
|
|
||
| register_provider(PROVIDER, modules=[transactions]) | ||
|
|
||
| __all__ = ["PROVIDER"] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| from context_use.providers.amex.transactions.pipe import AmexTransactionsPipe | ||
|
|
||
| __all__ = ["AmexTransactionsPipe"] |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
are there links we can paste here?