2020-02-26 17:22:13 +01:00
|
|
|
import re
|
|
|
|
|
2020-02-23 09:23:42 +01:00
|
|
|
import click
|
|
|
|
|
2020-03-31 18:32:54 +02:00
|
|
|
from ofx_processor.utils.base_ofx import OfxBaseProcessor, OfxBaseLine
|
2020-02-26 17:22:13 +01:00
|
|
|
|
|
|
|
|
2020-03-31 18:32:54 +02: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
|
2020-02-23 09:23:42 +01:00
|
|
|
|
|
|
|
|
2020-03-31 18:32:54 +02:00
|
|
|
class CeProcessor(OfxBaseProcessor):
|
2020-02-23 09:23:42 +01:00
|
|
|
account_name = "ce"
|
2020-02-26 17:22:13 +01:00
|
|
|
line_class = CeLine
|
2020-02-23 09:23:42 +01:00
|
|
|
|
|
|
|
@staticmethod
|
2020-02-29 18:26:32 +01:00
|
|
|
@click.command("ce")
|
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 CE bank statement (OFX file)."""
|
2020-02-23 09:23:42 +01:00
|
|
|
CeProcessor(ofx_filename).push_to_ynab()
|