From 40331a39bc711d8bf65263e0ebd5d6ddaae9e8d8 Mon Sep 17 00:00:00 2001 From: Gabriel Augendre Date: Wed, 26 Feb 2020 17:22:13 +0100 Subject: [PATCH] Update CE processing --- ofx_processor/processors/bpvf.py | 36 ++++++++++++++++---------------- ofx_processor/processors/ce.py | 20 +++++++++++++++++- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/ofx_processor/processors/bpvf.py b/ofx_processor/processors/bpvf.py index 23809a9..1372e3e 100644 --- a/ofx_processor/processors/bpvf.py +++ b/ofx_processor/processors/bpvf.py @@ -7,22 +7,6 @@ from ofxtools import OFXTree from ofx_processor.utils.processor import Processor, Line -def _process_name_and_memo(name, memo): - 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 - - class BpvfLine(Line): def __init__(self, data=None): super(BpvfLine, self).__init__(data) @@ -34,10 +18,26 @@ class BpvfLine(Line): return int(self.data.trnamt * 1000) def get_memo(self): - return _process_name_and_memo(self.data.name, self.data.memo)[1] + return self._process_name_and_memo(self.data.name, self.data.memo)[1] def get_payee(self): - return _process_name_and_memo(self.data.name, self.data.memo)[0] + 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 class BpvfProcessor(Processor): diff --git a/ofx_processor/processors/ce.py b/ofx_processor/processors/ce.py index 5ccdc6f..28fd032 100644 --- a/ofx_processor/processors/ce.py +++ b/ofx_processor/processors/ce.py @@ -1,10 +1,28 @@ +import re + import click -from ofx_processor.processors.bpvf import BpvfProcessor +from ofx_processor.processors.bpvf import BpvfProcessor, BpvfLine + + +class CeLine(BpvfLine): + @staticmethod + def _process_name_and_memo(name: str, memo: str): + name = name.strip() + cb_format = re.compile(r"FACT \d{6}$") + match = cb_format.search(name) + if match: + res_name = name[: match.start() - 1].strip() + res_memo = name[match.start() - 1 :].strip() + else: + res_name = name + res_memo = memo + return res_name, res_memo class CeProcessor(BpvfProcessor): account_name = "ce" + line_class = CeLine @staticmethod @click.command("ce", help="Process CE bank statement (OFX)")