Esempio n. 1
0
def import_transactions(csv_path):
    lines = []
    with open(csv_path, encoding='latin-1') as csv_file:
        for line in csv.reader(csv_file, delimiter=';'):
            if len(line) < 7:
                continue
            try:
                amount = float(line[11].replace('.', '').replace(',', '.'))
                if line[12] == 'S':
                    amount = -amount
                lines.append(
                    ImportStatement(
                        book_date=datetime.datetime.strptime(
                            line[1], '%d.%m.%Y').date(),
                        transaction_date=datetime.datetime.strptime(
                            line[0], '%d.%m.%Y').date(),
                        account=line[3],
                        notes=line[8],
                        iban=line[5],
                        amount=amount))
            except ValueError as e:
                # first line contains headers...
                print(e)
                pass
    return lines[1:-2]
Esempio n. 2
0
def import_csv(csv_path):
    lines = []
    with open(csv_path, encoding='latin-1') as csv_file:
        for line in csv.reader(csv_file, delimiter=';'):
            if len(line) < 6:
                continue
            try:
                lines.append(ImportStatement(
                    book_date=datetime.datetime.strptime(line[1], '%d.%m.%Y'),
                    transaction_date=datetime.datetime.strptime(line[2], '%d.%m.%Y'),
                    notes=line[3],
                    amount=float(line[4].replace('.', '').replace(',', '.'))
                    ))
            except ValueError:
                # first line contains headers
                pass
    return lines[1:]
Esempio n. 3
0
def import_transactions(ofx_path):
    transactions = []
    with open(ofx_path) as ofx_file:
        logger.info('Opening ofx file %s', ofx_path)
        try:
            ofx = OfxParser.parse(ofx_file)
            for transaction in ofx.account.statement.transactions:
                try:
                    transaction_time = transaction.date
                    transactions.append(ImportStatement(
                        notes=transaction.payee,
                        book_date=transaction_time.date(),
                        transaction_date=transaction_time.date(),
                        amount=transaction.amount
                        ))
                except ValueError:
                    logger.error('Cannot import transaction: {}'.format(transaction))
                    pass
        except ValueError:
            logger.error('Failed to import all transactions! Wrong file format?')

    return transactions
Esempio n. 4
0
def import_transactions(csv_path):
    lines = []
    with open(csv_path) as csv_file:
        logger.info('Opened csv file %s', csv_path)
        csviter = csv.reader(csv_file, delimiter=',')
        next(csviter)  # First line is header
        for line in csviter:
            logger.info('Line %s', line)
            try:
                transaction_time = datetime.datetime.strptime(
                    line[2], '%m/%d/%Y').date()
                lines.append(
                    ImportStatement(notes=line[0],
                                    account=line[1],
                                    book_date=transaction_time,
                                    transaction_date=transaction_time,
                                    amount=-float(line[4])))
            except ValueError as e:
                logger.error('Error' + e)
                pass

    return lines