mirror of
https://github.com/elisiariocouto/leggen.git
synced 2025-12-13 09:02:23 +00:00
47 lines
1.3 KiB
Python
47 lines
1.3 KiB
Python
import click
|
|
|
|
from leggen.main import cli
|
|
from leggen.utils.gocardless import REQUISITION_STATUS
|
|
from leggen.utils.network import get
|
|
from leggen.utils.text import datefmt, echo, info, print_table
|
|
|
|
|
|
@cli.command()
|
|
@click.pass_context
|
|
def status(ctx: click.Context):
|
|
"""
|
|
List all connected banks and their status
|
|
"""
|
|
|
|
res = get(ctx, "/requisitions/")
|
|
requisitions = []
|
|
accounts = []
|
|
for r in res["results"]:
|
|
requisitions.append(
|
|
{
|
|
"Bank": r["institution_id"],
|
|
"Status": REQUISITION_STATUS.get(r["status"], "UNKNOWN"),
|
|
"Created at": datefmt(r["created"]),
|
|
}
|
|
)
|
|
accounts += r.get("accounts", [])
|
|
info("Banks")
|
|
print_table(requisitions)
|
|
|
|
account_details = []
|
|
for account in accounts:
|
|
details = get(ctx, f"/accounts/{account}")
|
|
account_details.append(
|
|
{
|
|
"ID": details["id"],
|
|
"Bank": details["institution_id"],
|
|
"Status": details["status"],
|
|
"IBAN": details.get("iban", "N/A"),
|
|
"Created at": datefmt(details["created"]),
|
|
"Last accessed at": datefmt(details["last_accessed"]),
|
|
}
|
|
)
|
|
echo()
|
|
info("Accounts")
|
|
print_table(account_details)
|