Spaces:
Sleeping
Sleeping
Download api/reset.py from sbasu2512/stock-scraper: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/spaces/sbasu2512/stock-scraper/resolve/main/api/reset.py
- Command line
-
hf download hf://spaces/sbasu2512/stock-scraper/api/reset.py
-
curl -L -o reset.py https://huggingface.co/spaces/sbasu2512/stock-scraper/resolve/main/api/reset.py
1.56 kB
| """Administrative endpoints for replacing derived prediction data.""" | |
| from datetime import datetime | |
| from api.scheduler import IST | |
| from fastapi import APIRouter, Depends, HTTPException | |
| from api.auth import require_pipeline_guid | |
| from app.config import settings | |
| from database.repository import PredictionRepository | |
| from jobs.rebuild_predictions import rebuild_predictions | |
| router = APIRouter(prefix="/reset", tags=["reset-data"]) | |
| def purge_predictions() -> dict[str, object]: | |
| """Permanently remove all rows from the predictions table.""" | |
| deleted_rows = PredictionRepository(settings.DATABASE_URL).delete_all_predictions() | |
| return {"status": "purged", "deleted_rows": deleted_rows} | |
| def rebuild_preds() -> dict[str, object]: | |
| """Recreate predictions across every distinct trading date in OHLCV.""" | |
| now = datetime.now(IST) | |
| # Do not allow historical prediction rebuilds during the | |
| # daily production pipeline window: 15:00–17:00 IST. | |
| if 15 <= now.hour < 17: | |
| raise HTTPException( | |
| status_code=409, | |
| detail=( | |
| "Manual Prediction rebuild is disabled between " | |
| "3:00 PM and 5:00 PM IST." | |
| ), | |
| ) | |
| try: | |
| result = rebuild_predictions() | |
| except RuntimeError as exc: | |
| raise HTTPException(status_code=424, detail=str(exc)) from exc | |
| return {"status": "rebuilt", **result} | |