def parseMemorizedTransaction(cls_, chunk, date_format=DEFAULT_DATETIME_FORMAT): """ """ curItem = MemorizedTransaction() 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:Memorized'): continue 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] == '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 = Decimal(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
def parseMemorizedTransaction(cls_, chunk, date_format=None): """ """ curItem = MemorizedTransaction() 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:Memorized'): continue elif line[0] == 'T': curItem.amount = cls_.currencyToFloat(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] == '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_.currencyToFloat(line[1:-1]) else: # don't recognise this line; ignore it print ("Skipping unknown line:\n" + str(line), file=sys.stderr) 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
def parseMemorizedTransaction(cls_, chunk): """ """ curItem = MemorizedTransaction() 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 + 'Memorized'): continue 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] == '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] == '$': amt = cls_.parseFloat(line[1:-1]) if amt: if curItem.splits: split = curItem.splits[-1] split.amount = amt else: raise QifParserException('no split found') else: # don't recognize this line; ignore it print ("Skipping unknown line of memorized transaction:\n" + str(line)) return curItem