Update 2025-05-21_08:58:06
This commit is contained in:
27
streams.py
Normal file
27
streams.py
Normal file
@ -0,0 +1,27 @@
|
||||
# streams.py — Public streams endpoint for dicta2stream
|
||||
from fastapi import APIRouter
|
||||
from fastapi import APIRouter
|
||||
from pathlib import Path
|
||||
import json
|
||||
|
||||
router = APIRouter()
|
||||
|
||||
@router.get("/streams")
|
||||
def list_streams():
|
||||
txt_path = Path("./public_streams.txt")
|
||||
if not txt_path.exists():
|
||||
return {"streams": []}
|
||||
try:
|
||||
streams = []
|
||||
with txt_path.open("r") as f:
|
||||
for line in f:
|
||||
line = line.strip()
|
||||
if not line:
|
||||
continue
|
||||
try:
|
||||
streams.append(json.loads(line))
|
||||
except Exception:
|
||||
continue # skip malformed lines
|
||||
return {"streams": streams}
|
||||
except Exception:
|
||||
return {"streams": []}
|
Reference in New Issue
Block a user