From facf6ac94e533087846fca297520c311a81b6692 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Elisi=C3=A1rio=20Couto?= Date: Thu, 29 Feb 2024 17:15:52 +0000 Subject: [PATCH] fix: Deduplicate accounts. --- leggen/commands/balances.py | 4 ++-- leggen/commands/status.py | 4 ++-- leggen/commands/sync.py | 5 ++--- leggen/commands/transactions.py | 4 ++-- 4 files changed, 8 insertions(+), 9 deletions(-) diff --git a/leggen/commands/balances.py b/leggen/commands/balances.py index f7ae005..92b9389 100644 --- a/leggen/commands/balances.py +++ b/leggen/commands/balances.py @@ -13,9 +13,9 @@ def balances(ctx: click.Context): """ res = get(ctx, "/requisitions/") - accounts = [] + accounts = set() for r in res.get("results", []): - accounts += r.get("accounts", []) + accounts.update(r.get("accounts", [])) all_balances = [] for account in accounts: diff --git a/leggen/commands/status.py b/leggen/commands/status.py index a957b1d..76cc001 100644 --- a/leggen/commands/status.py +++ b/leggen/commands/status.py @@ -15,7 +15,7 @@ def status(ctx: click.Context): res = get(ctx, "/requisitions/") requisitions = [] - accounts = [] + accounts = set() for r in res["results"]: requisitions.append( { @@ -24,7 +24,7 @@ def status(ctx: click.Context): "Created at": datefmt(r["created"]), } ) - accounts += r.get("accounts", []) + accounts.update(r.get("accounts", [])) info("Banks") print_table(requisitions) diff --git a/leggen/commands/sync.py b/leggen/commands/sync.py index 93ca242..68281e5 100644 --- a/leggen/commands/sync.py +++ b/leggen/commands/sync.py @@ -104,10 +104,9 @@ def sync(ctx: click.Context): """ info("Getting accounts details") res = get(ctx, "/requisitions/") - accounts = [] + accounts = set() for r in res.get("results", []): - accounts += r.get("accounts", []) - accounts = list(set(accounts)) + accounts.update(r.get("accounts", [])) info(f"Syncing transactions for {len(accounts)} accounts") diff --git a/leggen/commands/transactions.py b/leggen/commands/transactions.py index ce16a80..db8c16f 100644 --- a/leggen/commands/transactions.py +++ b/leggen/commands/transactions.py @@ -41,9 +41,9 @@ def transactions(ctx: click.Context, account: str): print_transactions(ctx, account_info, account_transactions) else: res = get(ctx, "/requisitions/") - accounts = [] + accounts = set() for r in res["results"]: - accounts += r.get("accounts", []) + accounts.update(r.get("accounts", [])) for account in accounts: account_details = get(ctx, f"/accounts/{account}") account_transactions = get(ctx, f"/accounts/{account}/transactions/").get(