1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54
|
import csv
import re
from ofxstatement import statement
from ofxstatement.parser import CsvStatementParser
from ofxstatement.plugin import Plugin
from ofxstatement.statement import Statement
class WalutomatPlugin(Plugin):
"""Walutomat (www.walutomat.pl) CSV history plugin
"""
def get_parser(self, filename):
encoding = self.settings.get('charset', 'utf8')
f = open(filename, "r", encoding=encoding)
parser = WalutomatParser(f)
parser.statement.currency = self.settings.get('currency', '')
parser.statement.bank_id = self.settings.get('bank', 'walutomat')
parser.statement.account_id = self.settings.get('account', '')
parser.swap_payee_and_memo = self.settings.get('swap-payee-and-memo', True)
return parser
class WalutomatParser(CsvStatementParser):
mappings = {"id": 0,
"date": 1,
"amount": 2,
"memo": 5 }
date_format = "%Y-%m-%d %H:%M:%S"
def split_records(self):
return csv.reader(self.fin, delimiter=';', quotechar='"')
def parse_record(self, line):
if self.cur_record == 1:
return None
if not self.statement.currency:
self.statement.currency = line[4]
if not self.statement.account_id:
self.statement.account_id = line[4]
if self.statement.currency != line[4]:
return None
sl = super(WalutomatParser, self).parse_record(line)
if getattr(self, 'swap_payee_and_memo', False):
sl.memo, sl.payee = sl.payee, sl.memo
return sl
def parse_float(self, value):
return super(WalutomatParser, self).parse_float(re.sub("[ ,a-zA-Z]", "", value))
|