How to use the pynubank.Nubank function in pynubank

To help you get started, we’ve selected a few pynubank examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github andreroggeri / nubank-sync-ynab / nubank_sync_ynab / sync.py View on Github external
YNAB_EMAIL = os.getenv('YNAB_EMAIL')
YNAB_PASSWORD = os.getenv('YNAB_PASSWORD')
YNAB_BUDGET = os.getenv('YNAB_BUDGET')
NUBANK_TOKEN = os.getenv('NUBANK_TOKEN')
NUBANK_CERT = os.getenv('NUBANK_CERT')
STARTING_POINT = datetime.datetime.strptime(os.getenv('STARTING_POINT'), '%Y-%m-%d').date()

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)} 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()
        )

    ynab.sync()

pynubank

MIT
Latest version published 1 year ago

Package Health Score

50 / 100
Full package analysis