import os
import time
from .audit import audit_tool_call
import requests

LITEFARM_BASE_URL = os.getenv("LITEFARM_BASE_URL", "http://localhost:9000")


def export_aggregates():
    _t = time.time()
    url = f"{LITEFARM_BASE_URL}/api/aggregates"
    r = requests.get(url, timeout=20)
    r.raise_for_status()
    out = r.json()
    audit_tool_call("tool_litefarm_read.export_aggregates", {}, {"ok": True}, True, int((time.time()-_t)*1000))
    return out
