mirror of
https://github.com/elisiariocouto/leggen.git
synced 2025-12-13 11:22:21 +00:00
fix(cli): Show transactions without internal ID when using --full.
This commit is contained in:
committed by
Elisiário Couto
parent
6bce7eb6be
commit
46f3f5c498
@@ -51,9 +51,13 @@ def transactions(ctx: click.Context, account: str, limit: int, full: bool):
|
||||
# Full transaction details
|
||||
formatted_transactions = []
|
||||
for txn in transactions_data:
|
||||
# Handle optional internal_transaction_id
|
||||
txn_id = txn.get("internal_transaction_id")
|
||||
txn_id_display = txn_id[:12] + "..." if txn_id else "N/A"
|
||||
|
||||
formatted_transactions.append(
|
||||
{
|
||||
"ID": txn["internal_transaction_id"][:12] + "...",
|
||||
"ID": txn_id_display,
|
||||
"Date": datefmt(txn["transaction_date"]),
|
||||
"Description": txn["description"][:50] + "..."
|
||||
if len(txn["description"]) > 50
|
||||
@@ -67,6 +71,9 @@ def transactions(ctx: click.Context, account: str, limit: int, full: bool):
|
||||
# Summary view
|
||||
formatted_transactions = []
|
||||
for txn in transactions_data:
|
||||
# Handle optional internal_transaction_id
|
||||
txn_id = txn.get("internal_transaction_id")
|
||||
|
||||
formatted_transactions.append(
|
||||
{
|
||||
"Date": datefmt(txn["date"]),
|
||||
|
||||
@@ -8,6 +8,19 @@ from loguru import logger
|
||||
from leggend.config import config
|
||||
|
||||
|
||||
def _log_rate_limits(response):
|
||||
"""Log GoCardless API rate limit headers"""
|
||||
limit = response.headers.get("X-RateLimit-Limit")
|
||||
remaining = response.headers.get("X-RateLimit-Remaining")
|
||||
reset = response.headers.get("X-RateLimit-Reset")
|
||||
account_success_reset = response.headers.get("X-RateLimit-Account-Success-Reset")
|
||||
|
||||
if limit or remaining or reset or account_success_reset:
|
||||
logger.info(
|
||||
f"GoCardless rate limits - Limit: {limit}, Remaining: {remaining}, Reset: {reset}s, Account Success Reset: {account_success_reset}"
|
||||
)
|
||||
|
||||
|
||||
class GoCardlessService:
|
||||
def __init__(self):
|
||||
self.config = config.gocardless_config
|
||||
@@ -42,6 +55,7 @@ class GoCardlessService:
|
||||
f"{self.base_url}/token/refresh/",
|
||||
json={"refresh": auth["refresh"]},
|
||||
)
|
||||
_log_rate_limits(response)
|
||||
response.raise_for_status()
|
||||
auth.update(response.json())
|
||||
self._save_auth(auth)
|
||||
@@ -69,6 +83,7 @@ class GoCardlessService:
|
||||
"secret_key": self.config["secret"],
|
||||
},
|
||||
)
|
||||
_log_rate_limits(response)
|
||||
response.raise_for_status()
|
||||
auth = response.json()
|
||||
self._save_auth(auth)
|
||||
@@ -95,6 +110,7 @@ class GoCardlessService:
|
||||
headers=headers,
|
||||
params={"country": country},
|
||||
)
|
||||
_log_rate_limits(response)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
@@ -109,6 +125,7 @@ class GoCardlessService:
|
||||
headers=headers,
|
||||
json={"institution_id": institution_id, "redirect": redirect_url},
|
||||
)
|
||||
_log_rate_limits(response)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
@@ -119,6 +136,7 @@ class GoCardlessService:
|
||||
response = await client.get(
|
||||
f"{self.base_url}/requisitions/", headers=headers
|
||||
)
|
||||
_log_rate_limits(response)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
@@ -129,6 +147,7 @@ class GoCardlessService:
|
||||
response = await client.get(
|
||||
f"{self.base_url}/accounts/{account_id}/", headers=headers
|
||||
)
|
||||
_log_rate_limits(response)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
@@ -139,6 +158,7 @@ class GoCardlessService:
|
||||
response = await client.get(
|
||||
f"{self.base_url}/accounts/{account_id}/balances/", headers=headers
|
||||
)
|
||||
_log_rate_limits(response)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
@@ -149,5 +169,6 @@ class GoCardlessService:
|
||||
response = await client.get(
|
||||
f"{self.base_url}/accounts/{account_id}/transactions/", headers=headers
|
||||
)
|
||||
_log_rate_limits(response)
|
||||
response.raise_for_status()
|
||||
return response.json()
|
||||
|
||||
Reference in New Issue
Block a user