ofx-processor/ofx_processor/processors/ce.py

39 lines
1.1 KiB
Python
Raw Normal View History

2020-02-26 17:22:13 +01:00
import re
2021-11-18 19:06:40 +01:00
from ofx_processor.utils.base_ofx import OfxBaseLine, OfxBaseProcessor
2020-02-26 17:22:13 +01:00
class CeLine(OfxBaseLine):
def get_memo(self):
return self._process_name_and_memo(self.data.name, self.data.memo)[1]
def get_payee(self):
return self._process_name_and_memo(self.data.name, self.data.memo)[0]
2020-02-26 17:22:13 +01:00
@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(OfxBaseProcessor):
account_name = "ce"
command_name = "ce"
2020-02-26 17:22:13 +01:00
line_class = CeLine
def main(filename, keep, send_method):
"""Import CE bank statement (OFX file)."""
2021-12-04 11:35:26 +01:00
processor = CeProcessor(filename)
if send_method:
processor.send_reconciled_amount(send_method)
2021-12-04 11:35:26 +01:00
processor.push_to_ynab(keep)