def parse_record(self, line): if line[0] == "Kontonummer": # it's the table header return None if len(line) < 3: """e.g.: ['# 1 vorgemerkte Umsätze nicht angezeigt']""" return None if not line[2]: return None if self.statement.account_id is None: self.statement.account_id = line[0] sl = StatementLine() sl.id = line[1] sl.date = self.parse_datetime(line[2]) sl.date_avail = self.parse_datetime(line[3]) sl.amount = self.parse_float(line[4]) sl.trntype = TMAPPINGS.get(line[5], 'DEBIT' if sl.amount < 0 else 'CREDIT') sl.payee = line[7][:32] sl.memo = "%s: %s" % (line[6], " ".join(x for x in line[13:31] if len(x) > 0)) if len(line[8]) > 0 and len(line[9]) > 0: # additional bank information is present splitted = self.parse_iban(line[8]) if splitted: sl.bank_account_to = BankAccount(**splitted) else: sl.bank_account_to = BankAccount(line[9], line[8]) return sl
def parse_record(self, line): if self.cur_record < 2: return None m = None parse_info = None if len(line) == 11: m = self.mt940_mappings parse_info = self.parse_transaction_info_mt940 elif len(line) == 17: m = self.camt_mappings parse_info = self.parse_transaction_info_camt else: raise ValueError("invalid input line: '%s'" % line) if self.statement.account_id is None: self.statement.account_id = line[m["accid"]] sl = StatementLine() sl.date_avail = self.parse_datetime(line[m["valdate"]]) if len(line[m["date"]]) > 0: sl.date = self.parse_datetime(line[m["date"]]) else sl.date = sl.date_avail sl.amount = self.parse_float(line[m["amount"]]) sl.trntype = self.parse_transaction_type(sl.amount, line[m["btext"]]) # remove leading or all) zeros line[m["toaccid"]] = line[m["toaccid"]].lstrip('0') if len(line[m["toaccid"]]) > 0 and len(line[m["tobankid"]]) > 0: # additional bank information is present splitted = self.parse_iban(line[m["toaccid"]]) if splitted: sl.bank_account_to = BankAccount(**splitted) else: sl.bank_account_to = BankAccount(line[m["tobankid"]], line[m["toaccid"]]) if line[m["currency"]] != self.statement.currency: # different currency is used sl.currency = line[m["currency"]] # remove additional spaces in the payee sl.payee = re.sub(' +', ' ', line[m["payee"]])[:32] info = parse_info(line) # remove additional spaces in the memo sl.memo = "%s: %s" % (line[m["btext"]], re.sub(' +', ' ', info["memo"].strip())) # we need to generate an ID because nothing is given sl.id = generate_stable_transaction_id(sl) return sl
def parse_record(self, line): if len(line) < 5: return None elif len(line) < 12: # possibly meta information about the account if "BLZ" in line[0]: self.statement.bank_id = line[1] elif "Konto" in line[0]: self.statement.account_id = line[1] return None if line[9] == "Anfangssaldo": self.statement.start_date = self.parse_datetime(line[0]) self.statement.start_balance = self.parse_float(line[11]) return None elif line[9] == "Endsaldo": self.statement.end_date = self.parse_datetime(line[0]) self.statement.end_balance = self.parse_float(line[11]) return None elif line[0] == "Buchungstag": # it's the table header return None sl = StatementLine() sl.date = self.parse_datetime(line[0]) sl.date_avail = self.parse_datetime(line[1]) # Note: amount has no sign. We need to guess it later... sl.amount = self.parse_float(line[11]) info = self.parse_transaction_info(line) sl.amount *= info["sign"] sl.trntype = info["ttype"] if "iban" in info: # additional bank information if present sl.bank_account_to = BankAccount(**self.parse_iban(info["iban"])) if line[10] != self.statement.currency: # different currency is used sl.currency = line[10] # remove additional spaces in the payee sl.payee = re.sub(" +", " ", line[3].replace("\n", " ").strip())[:32] # remove additional spaces in the memo sl.memo = re.sub(" +", " ", info["memo"].strip()) # we need to generate an ID because nothing is given sl.id = generate_stable_transaction_id(sl) return sl