2020-03-31 18:32:54 +02:00
|
|
|
import sys
|
|
|
|
|
|
|
|
import click
|
|
|
|
|
|
|
|
from ofx_processor.utils.base_ofx import OfxBaseLine, OfxBaseProcessor
|
|
|
|
|
|
|
|
|
|
|
|
class LclLine(OfxBaseLine):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
class LclProcessor(OfxBaseProcessor):
|
|
|
|
line_class = LclLine
|
|
|
|
account_name = "lcl"
|
2020-05-08 18:02:25 +02:00
|
|
|
command_name = "lcl"
|
2020-03-31 18:32:54 +02:00
|
|
|
|
|
|
|
def parse_file(self):
|
|
|
|
# The first line of this file needs to be removed.
|
|
|
|
# It contains something that is not part of the header of an OFX file.
|
|
|
|
try:
|
|
|
|
with open(self.filename, "r") as user_file:
|
|
|
|
data = user_file.read().splitlines(True)
|
|
|
|
except FileNotFoundError:
|
|
|
|
click.secho("Couldn't find ofx file", fg="red")
|
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
if "Content-Type:" in data[0]:
|
|
|
|
with open(self.filename, "w") as temp_file:
|
|
|
|
temp_file.writelines(data[1:])
|
|
|
|
|
|
|
|
transactions = super(LclProcessor, self).parse_file()
|
|
|
|
|
|
|
|
if "Content-Type:" in data[0]:
|
|
|
|
with open(self.filename, "w") as temp_file:
|
|
|
|
temp_file.writelines(data)
|
|
|
|
|
|
|
|
return transactions
|
|
|
|
|
2020-05-08 18:02:25 +02:00
|
|
|
|
|
|
|
def main(filename, keep):
|
|
|
|
"""Import LCL bank statement (OFX file)."""
|
|
|
|
LclProcessor(filename).push_to_ynab(keep)
|