def parseTransaction(cls_, chunk, date_format=DEFAULT_DATE_FORMAT, decimal_sep=DEFAULT_DECIMAL_SEP, thousands_sep=DEFAULT_THOUSANDS_SEP): """ """ curItem = Transaction() 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:], date_format) elif line[0] == 'N': curItem.num = line[1:] 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] == '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:] 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:], 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
def parseTransaction(cls_, chunk): """ """ curItem = Transaction() if cls_.date_format: curItem.date_format = cls_.date_format lines = chunk.splitlines() for line in lines: if not len(line) or line[0] == '\n' or line.startswith(TYPE_HEADER): 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 = cls_.parseFloat(line[1:]) elif line[0] == 'U': curItem.uamount = cls_.parseFloat(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_.parseFloat(line[1:-1]) else: # don't recognize this line; ignore it print ("Skipping unknown line of transaction:\n" + str(line)) return curItem
def parseTransaction(cls_, chunk, date_format=DEFAULT_DATE_FORMAT, decimal_sep=DEFAULT_DECIMAL_SEP, thousands_sep=DEFAULT_THOUSANDS_SEP): """ """ curItem = Transaction() 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:], date_format) elif line[0] == 'N': curItem.num = line[1:] 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] == '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:] 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:], 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
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] == 'D': curItem.date = cls_.parseQifDateTime(line[1:]) elif line[0] == 'N': curItem.num = line[1:] elif line[0] == 'T': curItem.amount = convertFloat(line[1:]) elif line[0] == 'U': curItem.amount_U = convertFloat(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 = convertFloat(line[1:-1]) else: # don't recognise this line; ignore it print("Skipping unknown line:\n" + str(line)) return curItem