Spaces:
Sleeping
Sleeping
Download traffic.py from hizuk/purifai-api: direct link, hf CLI and curl.
- Browser
- Download file 916 Bytes
-
https://huggingface.co/spaces/hizuk/purifai-api/resolve/main/traffic.py
- Command line
-
hf download hf://spaces/hizuk/purifai-api/traffic.py
-
curl -L -o traffic.py https://huggingface.co/spaces/hizuk/purifai-api/resolve/main/traffic.py
916 Bytes
| from fastapi import APIRouter, Request | |
| from utils import get_supabase | |
| from datetime import datetime | |
| router = APIRouter() | |
| async def traffic_scans(since: str = None): | |
| """ | |
| Return scans newer than `since` (ISO format). | |
| The dashboard polls this every few seconds. | |
| """ | |
| try: | |
| supabase = get_supabase() | |
| query = supabase.table("scans").select("*").order("timestamp", desc=True).limit(100) | |
| if since: | |
| query = query.gt("timestamp", since) | |
| response = query.execute() | |
| scans = response.data if response.data else [] | |
| # Calculate metrics for the response (or get from another table if cached) | |
| # For MVP, we can calculate them on the fly or just return the scans | |
| return { | |
| "scans": scans | |
| } | |
| except Exception as e: | |
| return {"scans": [], "error": str(e)} | |