Last active
June 24, 2022 23:48
-
-
Save basst85/028f9747b006ad96574b6d67008c1bb1 to your computer and use it in GitHub Desktop.
bunq_monetaryaccount_list.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
import warnings | |
from bunq.sdk import context | |
from bunq.sdk.json import converter | |
from bunq.sdk.client import Pagination | |
from bunq.sdk.context import ApiContext | |
from bunq.sdk.context import ApiEnvironmentType | |
from bunq.sdk.context import BunqContext | |
from bunq.sdk.model.generated import endpoint | |
from bunq.sdk.model.generated.object_ import Pointer, Amount | |
warnings.filterwarnings("ignore") | |
_API_KEY = '<YOUR SANDBOX API KEY>' | |
_DEVICE_DESCRIPTION = 'TestPython' | |
_CONFIG_FILE_LOCATION = './bunq_sandbox.conf' | |
def run(): | |
ApiContext( | |
ApiEnvironmentType.SANDBOX, | |
_API_KEY, | |
_DEVICE_DESCRIPTION).save(_CONFIG_FILE_LOCATION) | |
api_context = ApiContext.restore(_CONFIG_FILE_LOCATION) | |
api_context.ensure_session_active() | |
api_context.save(_CONFIG_FILE_LOCATION) | |
BunqContext.load_api_context(api_context) | |
pagination = Pagination() | |
pagination.count = 25 | |
monetaryaccount_list = endpoint.MonetaryAccount.list( | |
params=pagination.url_params_count_only) | |
for monetaryaccount in monetaryaccount_list.value: | |
pointer_iban = get_first_pointer_iban(monetaryaccount.MonetaryAccountBank) | |
print(f'''Description: {monetaryaccount.MonetaryAccountBank.description} | |
IBAN: {pointer_iban.value}''') | |
def get_first_pointer_iban(monetary_account_bank): | |
for alias in monetary_account_bank.alias: | |
if alias.type_ == 'IBAN': | |
return alias | |
# Run it only if called from the command line | |
if __name__ == '__main__': | |
run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment