Exemplo n.º 1
0
STARTING_POINT = datetime.datetime.strptime(os.getenv('STARTING_POINT'),
                                            '%Y-%m-%d').date()

IN_EVENT = ['TransferInEvent', 'TransferOutReversalEvent']

if __name__ == '__main__':
    with open('cert.p12', 'wb') as f:
        cert_content = base64.b64decode(NUBANK_CERT)
        f.write(cert_content)

    log_config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                   'logging.json')
    setup_logging(log_config_file)
    ynab = YNAB(YNAB_EMAIL, YNAB_PASSWORD, YNAB_BUDGET)
    nu = Nubank()
    nu.authenticate_with_refresh_token(NUBANK_TOKEN, './cert.p12')

    transactions = filter_transactions(nu.get_card_statements(),
                                       STARTING_POINT)

    print(f'Found {len(transactions)} card transactions')
    for transaction in transactions:
        ynab.add_transaction(payee=transaction['description'],
                             date=parse_transaction_date(transaction),
                             value=-int(transaction['amount']) / 100,
                             id=transaction['id'],
                             subcategory=transaction['category'].capitalize(),
                             account=NUBANK_CARD_ACCOUNT)

    account_transactions = filter_transactions(nu.get_account_statements(),
                                               STARTING_POINT)
Exemplo n.º 2
0
    transaction["detail"] = transaction['detail'].split(' - ')[0]
    if "amount" in transaction:
        transaction["amount"] = '{:.2f}'.format(transaction['amount']).replace(
            '.', ',')
    return transaction.values()


if __name__ == '__main__':
    log_config_file = os.path.join(os.path.dirname(os.path.abspath(__file__)),
                                   'logging.json')
    setup_logging(log_config_file)

    logging.info('Initializen Nubank export')

    nu = Nubank()
    nu.authenticate_with_refresh_token(NUBANK_TOKEN, NUBANK_CERT)

    account_transactions = nu.get_account_feed()
    logging.info(f'Found {len(account_transactions)} account transactions')

    with open('export.csv', mode='w', encoding='utf-8') as tfile:
        fieldnames = [
            'id', '__typename', 'title', 'detail', 'postDate', 'amount',
            'originAccount', 'destinationAccount'
        ]
        writer = csv.DictWriter(tfile,
                                delimiter=';',
                                quotechar='"',
                                quoting=csv.QUOTE_MINIMAL,
                                fieldnames=fieldnames)