2020-02-22 15:25:51 +01:00
|
|
|
import re
|
2020-02-22 18:26:51 +01:00
|
|
|
|
|
|
|
import click
|
2020-02-22 15:25:51 +01:00
|
|
|
|
2020-03-31 18:32:54 +02:00
|
|
|
from ofx_processor.utils.base_ofx import OfxBaseLine, OfxBaseProcessor
|
2020-02-22 15:25:51 +01:00
|
|
|
|
|
|
|
|
2020-03-31 18:32:54 +02:00
|
|
|
class BpvfLine(OfxBaseLine):
|
2020-02-22 15:25:51 +01:00
|
|
|
def get_memo(self):
|
2020-02-26 17:22:13 +01:00
|
|
|
return self._process_name_and_memo(self.data.name, self.data.memo)[1]
|
2020-02-22 15:25:51 +01:00
|
|
|
|
|
|
|
def get_payee(self):
|
2020-02-26 17:22:13 +01:00
|
|
|
return self._process_name_and_memo(self.data.name, self.data.memo)[0]
|
|
|
|
|
|
|
|
@staticmethod
|
|
|
|
def _process_name_and_memo(name: str, memo: str):
|
|
|
|
if "CB****" in name:
|
|
|
|
conversion = re.compile(r"\d+,\d{2}[a-zA-Z]{3}")
|
|
|
|
match = conversion.search(memo)
|
|
|
|
if match:
|
|
|
|
res_name = memo[: match.start() - 1]
|
|
|
|
res_memo = name + memo[match.start() - 1 :]
|
|
|
|
else:
|
|
|
|
res_name = memo
|
|
|
|
res_memo = name
|
|
|
|
|
|
|
|
return res_name, res_memo
|
|
|
|
|
|
|
|
return name, memo
|
2020-02-22 15:25:51 +01:00
|
|
|
|
|
|
|
|
2020-03-31 18:32:54 +02:00
|
|
|
class BpvfProcessor(OfxBaseProcessor):
|
2020-02-22 15:25:51 +01:00
|
|
|
line_class = BpvfLine
|
2020-02-22 18:26:51 +01:00
|
|
|
account_name = "bpvf"
|
|
|
|
|
2020-02-23 09:23:42 +01:00
|
|
|
@staticmethod
|
2020-02-29 18:26:32 +01:00
|
|
|
@click.command("bpvf")
|
2020-02-23 09:23:42 +01:00
|
|
|
@click.argument("ofx_filename")
|
|
|
|
def main(ofx_filename):
|
2020-02-29 18:26:32 +01:00
|
|
|
"""Import BPVF bank statement (OFX file)."""
|
2020-02-23 09:23:42 +01:00
|
|
|
BpvfProcessor(ofx_filename).push_to_ynab()
|