Add get_all_accounts() method to FavaClient for account sync
This commit is contained in:
parent
4a3922895e
commit
a210d7433a
1 changed files with 43 additions and 0 deletions
|
|
@ -816,6 +816,49 @@ class FavaClient:
|
||||||
limit=limit
|
limit=limit
|
||||||
)
|
)
|
||||||
|
|
||||||
|
async def get_all_accounts(self) -> List[Dict[str, Any]]:
|
||||||
|
"""
|
||||||
|
Get all accounts from Beancount/Fava.
|
||||||
|
|
||||||
|
Returns:
|
||||||
|
List of account dictionaries:
|
||||||
|
[
|
||||||
|
{"account": "Assets:Cash", "meta": {...}},
|
||||||
|
{"account": "Expenses:Food", "meta": {...}},
|
||||||
|
...
|
||||||
|
]
|
||||||
|
|
||||||
|
Example:
|
||||||
|
accounts = await fava.get_all_accounts()
|
||||||
|
for acc in accounts:
|
||||||
|
print(acc["account"]) # "Assets:Cash"
|
||||||
|
"""
|
||||||
|
try:
|
||||||
|
# Use Fava's /api/accounts endpoint
|
||||||
|
async with httpx.AsyncClient(timeout=self.timeout) as client:
|
||||||
|
response = await client.get(f"{self.base_url}/api/accounts")
|
||||||
|
response.raise_for_status()
|
||||||
|
accounts_data = response.json()
|
||||||
|
|
||||||
|
# Fava returns array of account names
|
||||||
|
# We need to convert to dict format expected by account_sync
|
||||||
|
accounts = []
|
||||||
|
for acc_name in accounts_data:
|
||||||
|
accounts.append({
|
||||||
|
"account": acc_name,
|
||||||
|
"meta": {} # Fava /api/accounts doesn't include metadata
|
||||||
|
})
|
||||||
|
|
||||||
|
logger.debug(f"Fava returned {len(accounts)} accounts")
|
||||||
|
return accounts
|
||||||
|
|
||||||
|
except httpx.HTTPStatusError as e:
|
||||||
|
logger.error(f"Fava accounts error: {e.response.status_code} - {e.response.text}")
|
||||||
|
raise
|
||||||
|
except httpx.RequestError as e:
|
||||||
|
logger.error(f"Fava connection error: {e}")
|
||||||
|
raise
|
||||||
|
|
||||||
async def get_journal_entries(self) -> List[Dict[str, Any]]:
|
async def get_journal_entries(self) -> List[Dict[str, Any]]:
|
||||||
"""
|
"""
|
||||||
Get all journal entries from Fava (with entry hashes).
|
Get all journal entries from Fava (with entry hashes).
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue