def parseTransaction(cls_, chunk, date_format=DEFAULT_DATETIME_FORMAT): """ """ curItem = Transaction() if date_format: curItem.date_format = DATETIME_FORMAT[date_format] lines = chunk.split('\n') for line in lines: if not len(line) or line[0] == '\n' or line.startswith('!Type'): continue elif line[0] == 'D': curItem.date = cls_.parseQifDateTime(line[1:]) elif line[0] == 'N': curItem.num = line[1:] elif line[0] == 'T': curItem.amount = Decimal(line[1:]) elif line[0] == 'C': curItem.cleared = line[1:] elif line[0] == 'P': curItem.payee = line[1:] elif line[0] == 'M': curItem.memo = line[1:] elif line[0] == '1': curItem.first_payment_date = line[1:] elif line[0] == '2': curItem.years_of_loan = line[1:] elif line[0] == '3': curItem.num_payments_done = line[1:] elif line[0] == '4': curItem.periods_per_year = line[1:] elif line[0] == '5': curItem.interests_rate = line[1:] elif line[0] == '6': curItem.current_loan_balance = line[1:] elif line[0] == '7': curItem.original_loan_amount = line[1:] elif line[0] == 'A': if not curItem.address: curItem.address = [] curItem.address.append(line[1:]) elif line[0] == 'L': cat = line[1:] if cat.startswith('['): curItem.to_account = cat[1:-1] else: curItem.category = cat elif line[0] == 'S': curItem.splits.append(AmountSplit()) split = curItem.splits[-1] cat = line[1:] if cat.startswith('['): split.to_account = cat[1:-1] else: split.category = cat elif line[0] == 'E': split = curItem.splits[-1] split.memo = line[1:-1] elif line[0] == 'A': split = curItem.splits[-1] if not split.address: split.address = [] split.address.append(line[1:]) elif line[0] == '$': split = curItem.splits[-1] split.amount = Decimal(line[1:]) else: # don't recognise this line; ignore it print("Skipping unknown line:\n" + str(line)) return curItem
def parseTransaction(cls_, chunk, date_format=None): """ """ curItem = Transaction() if date_format: curItem.date_format = date_format lines = chunk.split('\n') for line in lines: if not len(line) or line[0] == '\n' or line.startswith('!Type'): continue elif line[0] == '!': # Shouldn't happen. !Account Needs to be handled in main loop import pdb pdb.set_trace() elif line[0] == 'D': curItem.date = cls_.parseQifDateTime(line[1:]) elif line[0] == 'N': curItem.num = line[1:] elif line[0] in ('T', 'U'): curItem.amount = cls_.parseAmount(line[1:]) elif line[0] == 'C': curItem.cleared = line[1:] elif line[0] == 'P': curItem.payee = line[1:] elif line[0] == 'M': curItem.memo = line[1:] elif line[0] == '1': curItem.first_payment_date = line[1:] elif line[0] == '2': curItem.years_of_loan = line[1:] elif line[0] == '3': curItem.num_payments_done = line[1:] elif line[0] == '4': curItem.periods_per_year = line[1:] elif line[0] == '5': curItem.interests_rate = line[1:] elif line[0] == '6': curItem.current_loan_balance = line[1:] elif line[0] == '7': curItem.original_loan_amount = line[1:] elif line[0] == 'A': if not curItem.address: curItem.address = [] curItem.address.append(line[1:]) elif line[0] == 'L': cat = line[1:] if cat.startswith('['): curItem.to_account = cat[1:-1] else: curItem.category = cat elif line[0] == 'S': curItem.splits.append(AmountSplit()) split = curItem.splits[-1] cat = line[1:] if cat.startswith('['): split.to_account = cat[1:-1] else: split.category = cat elif line[0] == 'E': split = curItem.splits[-1] split.memo = line[1:-1] elif line[0] == 'A': split = curItem.splits[-1] if not split.address: split.address = [] split.address.append(line[1:]) elif line[0] == '$': split = curItem.splits[-1] split.amount = cls_.parseAmount(line[1:]) else: # don't recognise this line; ignore it print("Skipping unknown line:\n" + str(line)) return curItem
def parseMemorizedTransaction(cls_, chunk, date_format=DEFAULT_DATE_FORMAT, decimal_sep=DEFAULT_DECIMAL_SEP, thousands_sep=DEFAULT_THOUSANDS_SEP): """ """ curItem = MemorizedTransaction() lines = chunk.split('\n') for line in lines: if not len(line) or line[0] == '\n' or \ line.startswith('!Type:Memorized'): continue elif line[0] == 'T': curItem.amount = cls_.parseQifNumber( line[1:], decimal_sep=decimal_sep, thousands_sep=thousands_sep) elif line[0] == 'C': curItem.cleared = line[1:] elif line[0] == 'P': curItem.payee = line[1:] elif line[0] == 'M': curItem.memo = line[1:] elif line[0] == 'K': curItem.mtype = line[1:] elif line[0] == 'A': if not curItem.address: curItem.address = [] curItem.address.append(line[1:]) elif line[0] == 'L': cat = line[1:] if cat.startswith('['): curItem.to_account = cat[1:-1] else: curItem.category = cat elif line[0] == 'S': curItem.splits.append(AmountSplit()) split = curItem.splits[-1] cat = line[1:] if cat.startswith('['): split.to_account = cat[1:-1] else: split.category = cat elif line[0] == 'E': split = curItem.splits[-1] split.memo = line[1:-1] elif line[0] == 'A': split = curItem.splits[-1] if not split.address: split.address = [] split.address.append(line[1:]) elif line[0] == '$': split = curItem.splits[-1] split.amount = cls_.parseQifNumber(line[1:-1], decimal_sep=decimal_sep, thousands_sep=thousands_sep) else: # don't recognise this line; ignore it logger.warn("Skipping unknown line:\n" + str(line)) return curItem