import json from storage.directus import DirectusClient def export_to_json(filepath: str): calls = _export_from_directus() with open(filepath, "w", encoding="utf-8") as f: json.dump(calls, f, ensure_ascii=False, indent=2, default=str) def _export_from_directus() -> list[dict]: try: dc = DirectusClient() if not dc.is_available(): return [] all_calls = [] for col in ["calls", "calls_74951284933"]: resp = dc._client.get(f"/items/{col}") if resp.status_code == 200: all_calls.extend(resp.json().get("data", [])) dc.close() return all_calls except Exception: return []