Skip to content

Commit

Permalink
Allow specifying extra patterns for Revolut (#81)
Browse files Browse the repository at this point in the history
* Add extra_patterns

* Fix tests

* Change test
  • Loading branch information
mincong-h committed Jun 19, 2022
1 parent 6dbe33d commit ae44732
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 7 deletions.
2 changes: 2 additions & 0 deletions finance-tools.sample.yml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ accounts:
type: CHQ
id: 'astark2'
currency: USD
expressions:
- account-statement_(\d{4}-\d{2}-\d{2})_(\d{4}-\d{2}-\d{2})_en_(\w+)\.csv
label: Arya Stark - Revolut (US Dollar)

# Categories
Expand Down
22 changes: 15 additions & 7 deletions finance_toolkit/revolut.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from abc import ABCMeta
from pathlib import Path
from typing import Tuple
from typing import Tuple, List

import pandas as pd
from pandas import DataFrame
Expand All @@ -12,18 +12,26 @@

class RevolutAccount(Account):
def __init__(
self, account_type: str, account_id: str, account_num: str, currency: str
self,
account_type: str,
account_id: str,
account_num: str,
currency: str,
extra_patterns: List[str] = None,
):
patterns = [
r"Revolut-(.*)-Statement-(.*)\.csv",
r"account-statement_(\d{4}-\d{2}-\d{2})_(\d{4}-\d{2}-\d{2})_undefined-undefined_%s\.csv" # noqa
% account_num,
]
if extra_patterns:
patterns.extend(extra_patterns)
super().__init__(
account_type=account_type,
account_id=account_id,
account_num=account_num,
currency=currency,
patterns=[
r"Revolut-(.*)-Statement-(.*)\.csv",
r"account-statement_(\d{4}-\d{2}-\d{2})_(\d{4}-\d{2}-\d{2})_undefined-undefined_%s\.csv" # noqa
% account_num,
],
patterns=patterns,
)


Expand Down
1 change: 1 addition & 0 deletions finance_toolkit/tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def load_accounts(cls, raw: Dict) -> List[Account]:
account_id=symbolic_name,
account_num=fields["id"],
currency=fields["currency"],
extra_patterns=fields["expressions"] if "expressions" in fields else None,
)
)
elif company == "October":
Expand Down
3 changes: 3 additions & 0 deletions test/test_tx.py
Original file line number Diff line number Diff line change
Expand Up @@ -643,6 +643,9 @@ def test_configurator_parse_yaml(sample):
account_id="astark-REV-USD",
account_num="astark2",
currency="USD",
extra_patterns=[
r"account-statement_(\d{4}-\d{2}-\d{2})_(\d{4}-\d{2}-\d{2})_en_(\w+)\.csv"
],
),
BnpAccount(
account_type="LVA",
Expand Down

0 comments on commit ae44732

Please sign in to comment.