Calendar synchro

This commit is contained in:
OpenSquared
2026-06-28 12:15:25 +02:00
parent 98d6be8212
commit 79d4a9f741
6 changed files with 237 additions and 90 deletions

View File

@@ -12,6 +12,7 @@ class ApiKeysRequest(BaseModel):
newsapi_key: Optional[str] = None
eia_api_key: Optional[str] = None
fred_api_key: Optional[str] = None
calendar_refresh_h: Optional[str] = None
class SourcesRequest(BaseModel):
@@ -61,6 +62,9 @@ def update_api_keys(req: ApiKeysRequest):
if req.fred_api_key is not None:
set_config("fred_api_key", req.fred_api_key)
updated.append("fred")
if req.calendar_refresh_h is not None:
set_config("calendar_refresh_h", req.calendar_refresh_h)
updated.append("calendar_refresh_h")
return {"status": "ok", "updated": updated}

View File

@@ -570,6 +570,36 @@ def fxs_sync_status_ep() -> Dict[str, Any]:
return _fxs_sync_status
# ── Unified calendar sync ─────────────────────────────────────────────────────
def _run_calendar_sync(weeks_ahead: int):
from services.calendar_sync import calendar_sync
try:
calendar_sync(weeks_ahead=weeks_ahead)
except Exception as e:
logger.error(f"[eco/calendar-sync] Failed: {e}")
@router.post("/calendar-sync")
def calendar_sync_ep(
background_tasks: BackgroundTasks,
weeks: int = Query(8, ge=1, le=12),
) -> Dict[str, Any]:
"""Trigger unified calendar sync (FXStreet primary → FF fallback) in background."""
from services.calendar_sync import get_sync_status
if get_sync_status()["running"]:
raise HTTPException(409, "Calendar sync already running")
background_tasks.add_task(_run_calendar_sync, weeks)
return {"status": "started", "weeks_ahead": weeks}
@router.get("/calendar-sync/status")
def calendar_sync_status_ep() -> Dict[str, Any]:
"""Get unified calendar sync status (last_run, source, last_result, next_run)."""
from services.calendar_sync import get_sync_status
return get_sync_status()
@router.get("/calendar")
def ff_calendar(
period: str = Query("recent", description="recent|today|tomorrow|yesterday|this_week|next_week|previous_week|this_month|next_month|previous_month|custom"),