Use BQL query for get_all_accounts() instead of non-existent API endpoint
This commit is contained in:
parent
c70695f330
commit
ee2df73bcb
1 changed files with 15 additions and 19 deletions
|
|
@ -818,7 +818,7 @@ class FavaClient:
|
||||||
|
|
||||||
async def get_all_accounts(self) -> List[Dict[str, Any]]:
|
async def get_all_accounts(self) -> List[Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
Get all accounts from Beancount/Fava.
|
Get all accounts from Beancount/Fava using BQL query.
|
||||||
|
|
||||||
Returns:
|
Returns:
|
||||||
List of account dictionaries:
|
List of account dictionaries:
|
||||||
|
|
@ -834,29 +834,25 @@ class FavaClient:
|
||||||
print(acc["account"]) # "Assets:Cash"
|
print(acc["account"]) # "Assets:Cash"
|
||||||
"""
|
"""
|
||||||
try:
|
try:
|
||||||
# Use Fava's /api/accounts endpoint
|
# Use BQL to get all unique accounts
|
||||||
async with httpx.AsyncClient(timeout=self.timeout) as client:
|
query = "SELECT DISTINCT account"
|
||||||
response = await client.get(f"{self.base_url}/accounts")
|
result = await self.query_bql(query)
|
||||||
response.raise_for_status()
|
|
||||||
accounts_data = response.json()
|
|
||||||
|
|
||||||
# Fava returns array of account names
|
# Convert BQL result to expected format
|
||||||
# We need to convert to dict format expected by account_sync
|
|
||||||
accounts = []
|
accounts = []
|
||||||
for acc_name in accounts_data:
|
for row in result["rows"]:
|
||||||
|
account_name = row[0] if isinstance(row, list) else row.get("account")
|
||||||
|
if account_name:
|
||||||
accounts.append({
|
accounts.append({
|
||||||
"account": acc_name,
|
"account": account_name,
|
||||||
"meta": {} # Fava /api/accounts doesn't include metadata
|
"meta": {} # BQL doesn't return metadata easily
|
||||||
})
|
})
|
||||||
|
|
||||||
logger.debug(f"Fava returned {len(accounts)} accounts")
|
logger.debug(f"Fava returned {len(accounts)} accounts via BQL")
|
||||||
return accounts
|
return accounts
|
||||||
|
|
||||||
except httpx.HTTPStatusError as e:
|
except Exception as e:
|
||||||
logger.error(f"Fava accounts error: {e.response.status_code} - {e.response.text}")
|
logger.error(f"Failed to fetch accounts via BQL: {e}")
|
||||||
raise
|
|
||||||
except httpx.RequestError as e:
|
|
||||||
logger.error(f"Fava connection error: {e}")
|
|
||||||
raise
|
raise
|
||||||
|
|
||||||
async def get_journal_entries(self) -> List[Dict[str, Any]]:
|
async def get_journal_entries(self) -> List[Dict[str, Any]]:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue