def parse_record(self, line): san_line = {} for lkey, lval in line.items(): san_line[lkey] = re.sub("\$", "", lval) stmt_line = StatementLine() for field, col in self.mappings.items(): rawvalue = san_line[col] try: value = self.parse_value(rawvalue, field) except ValueError as e: # Invalid data line; skip it warning("Error parsing value '{}' on line '{}': {}".format(rawvalue, san_line, e)) return None setattr(stmt_line, field, value) if self.statement.filter_zeros and is_zero(stmt_line.amount): return None try: stmt_line.end_balance = float(san_line['Ending Balance']) except ValueError: # Usually indicates a pending transaction return None # generate transaction id out of available data stmt_line.id = generate_stable_transaction_id(stmt_line) return stmt_line
def parse_record(self, line): """Extracts the transaction data from the given line parsed from the JSON file. :param line: A transaction line from the parsed JSON file. :return: A new StatementLine filled by the given line's data. """ amount = to_float(line['amounts']['amount']) if self.statement.filter_zeros and is_zero(amount): return None memo = line['description'] datetime = ts_to_datetime(line['times']['when_recorded']) id = line['uuid'] ledger_amount = convert_debit(amount, line['bookkeeping_type']) stmt_line = StatementLine(id=id, date=datetime, memo=memo, amount=ledger_amount) stmt_line.end_balance = to_float(line['running_balance']) return stmt_line