Flask + React web UI with audio player, podcast queue, feed management, episode browser, music library, schedule viewer, and log tail. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
51 lines
1.3 KiB
Python
51 lines
1.3 KiB
Python
"""GET /api/schedule — schedule blocks with active indicator."""
|
|
|
|
from datetime import datetime
|
|
|
|
import yaml
|
|
from flask import Blueprint, jsonify
|
|
|
|
from ..config import STATION_CONFIG
|
|
|
|
bp = Blueprint("schedule", __name__)
|
|
|
|
DAY_NAMES = {1: "Mon", 2: "Tue", 3: "Wed", 4: "Thu", 5: "Fri", 6: "Sat", 7: "Sun"}
|
|
|
|
|
|
@bp.route("/schedule")
|
|
def get_schedule():
|
|
try:
|
|
with open(STATION_CONFIG) as f:
|
|
config = yaml.safe_load(f)
|
|
except Exception as e:
|
|
return jsonify({"error": str(e)}), 500
|
|
|
|
now = datetime.now()
|
|
current_day = now.isoweekday()
|
|
current_time = now.strftime("%H:%M")
|
|
|
|
blocks = []
|
|
for block in config.get("schedule", []):
|
|
days = block.get("days", [])
|
|
start = block.get("start", "00:00")
|
|
end = block.get("end", "23:59")
|
|
|
|
is_active = False
|
|
if current_day in days:
|
|
if start <= end:
|
|
is_active = start <= current_time <= end
|
|
else:
|
|
is_active = current_time >= start or current_time <= end
|
|
|
|
blocks.append({
|
|
"name": block.get("name"),
|
|
"days": days,
|
|
"day_names": [DAY_NAMES.get(d, str(d)) for d in days],
|
|
"start": start,
|
|
"end": end,
|
|
"folder": block.get("folder"),
|
|
"active": is_active,
|
|
})
|
|
|
|
return jsonify(blocks)
|