From 758a3a2257c490a92fb0b0673c74d720ad7e87f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elisi=C3=A1rio=20Couto?= Date: Fri, 5 Jul 2024 10:54:24 +0100 Subject: [PATCH] fix(sync): Continue on account deactivation. --- leggen/commands/sync.py | 44 ++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 23 deletions(-) diff --git a/leggen/commands/sync.py b/leggen/commands/sync.py index bb22970..5aacf30 100644 --- a/leggen/commands/sync.py +++ b/leggen/commands/sync.py @@ -41,30 +41,28 @@ def sync(ctx: click.Context): info(f"Syncing balances for {len(accounts)} accounts") for account in accounts: - account_details = get(ctx, f"/accounts/{account}") - account_balances = get(ctx, f"/accounts/{account}/balances/").get( - "balances", [] - ) - for balance in account_balances: - balance_amount = balance["balanceAmount"] - amount = round(float(balance_amount["amount"]), 2) - balance_document = { - "account_id": account, - "bank": account_details["institution_id"], - "status": account_details["status"], - "iban": account_details.get("iban", "N/A"), - "amount": amount, - "currency": balance_amount["currency"], - "type": balance["balanceType"], - "timestamp": datetime.datetime.now().timestamp(), - } - try: + try: + account_details = get(ctx, f"/accounts/{account}") + account_balances = get(ctx, f"/accounts/{account}/balances/").get( + "balances", [] + ) + for balance in account_balances: + balance_amount = balance["balanceAmount"] + amount = round(float(balance_amount["amount"]), 2) + balance_document = { + "account_id": account, + "bank": account_details["institution_id"], + "status": account_details["status"], + "iban": account_details.get("iban", "N/A"), + "amount": amount, + "currency": balance_amount["currency"], + "type": balance["balanceType"], + "timestamp": datetime.datetime.now().timestamp(), + } persist_balance(ctx, account, balance_document) - except Exception as e: - error( - f"[{account}] Error: Sync failed, skipping account, exception: {e}" - ) - continue + except Exception as e: + error(f"[{account}] Error: Sync failed, skipping account, exception: {e}") + continue info(f"Syncing transactions for {len(accounts)} accounts")