Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
25 lines
712 B
Python
25 lines
712 B
Python
"""channels.json (written by gen_config.py): {"groups": {...}, "channels": {freq_hz: {label, group, ...}}}."""
|
|
import json
|
|
import os
|
|
|
|
from radio.config import CHANNELS_FILE
|
|
|
|
_chan = {"mtime": 0, "data": {"groups": {}, "channels": {}}}
|
|
|
|
|
|
def channels():
|
|
"""Parsed channels.json, re-read when its mtime changes; the last good copy is kept on read errors."""
|
|
try:
|
|
m = os.stat(CHANNELS_FILE).st_mtime
|
|
if m != _chan["mtime"]:
|
|
with open(CHANNELS_FILE, encoding="utf-8") as fh:
|
|
_chan["data"] = json.load(fh)
|
|
_chan["mtime"] = m
|
|
except (OSError, ValueError):
|
|
pass
|
|
return _chan["data"]
|
|
|
|
|
|
def groups():
|
|
return channels().get("groups", {})
|