Initial commit: SSS 50-week LAN check-in app.

Ship the Synology/Mac deployable player with curriculum mapping, stats, and resource library.

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
optimxandCursor committed 2026-11-04 23:11:42 +08:00
commit dd281e1bd0
27 files changed
+9416

No files matched your search

+116
View File
@@ -0,0 +1,116 @@
#!/usr/bin/env python3
"""Build curriculum.json from the workbook and unified SSS asset root."""
from __future__ import annotations
import argparse
import json
import re
from pathlib import Path
from openpyxl import load_workbook
SONG_PATTERN = re.compile(r"^(\d+)-(\d+)\s+(.+)$")
REVIEW_PATTERN = re.compile(r"复习(\d+)-(\d+)周")
ASSET_SPECS = {
"video_file": ("视频", ".mp4"),
"audio_file": ("音频", ".mp3"),
"lyrics_file": ("歌词", ".jpg"),
}
def files_by_song_id(folder: Path, extension: str) -> dict[str, str]:
result = {}
for path in sorted(folder.glob(f"*{extension}")):
match = re.match(r"^(\d+-\d+)\s+", path.stem)
if match:
result[match.group(1)] = path.name
return result
def build_curriculum(workbook_path: Path, asset_root: Path) -> dict:
workbook = load_workbook(workbook_path, data_only=True, read_only=True)
worksheet = workbook["50周打卡"]
assets = {
field: files_by_song_id(asset_root / folder, extension)
for field, (folder, extension) in ASSET_SPECS.items()
}
weeks: dict[int, dict] = {}
current_week = None
for week_value, category_value, song_value in worksheet.iter_rows(
min_row=3, max_col=3, values_only=True
):
if isinstance(week_value, int):
current_week = week_value
category = str(category_value or "").strip()
review_match = REVIEW_PATTERN.search(category)
weeks[current_week] = {
"number": current_week,
"kind": "review" if review_match else "lesson",
"category": category,
"songs": [],
}
if review_match:
weeks[current_week]["review_from"] = int(review_match.group(1))
weeks[current_week]["review_to"] = int(review_match.group(2))
if current_week is None or not isinstance(song_value, str):
continue
match = SONG_PATTERN.match(song_value.strip())
if not match:
continue
song_id = f"{match.group(1)}-{match.group(2)}"
song = {
"id": song_id,
"slot": int(match.group(2)),
"title": match.group(3),
}
for field, mapping in assets.items():
if song_id not in mapping:
raise RuntimeError(f"Missing {field} for {song_id}")
song[field] = mapping[song_id]
weeks[current_week]["songs"].append(song)
if sorted(weeks) != list(range(1, 51)):
raise RuntimeError("Workbook must contain weeks 1 through 50")
songs = [song for week in weeks.values() for song in week["songs"]]
song_ids = {song["id"] for song in songs}
for field, mapping in assets.items():
unused = sorted(set(mapping) - song_ids)
if unused:
raise RuntimeError(f"Unused {field}: {unused}")
return {
"meta": {
"title": "SSS 50周学习计划",
"source_workbook": workbook_path.name,
"asset_root_name": asset_root.name,
"song_count": len(songs),
"week_count": 50,
},
"weeks": [weeks[number] for number in sorted(weeks)],
}
def main() -> None:
parser = argparse.ArgumentParser()
parser.add_argument("workbook", type=Path)
parser.add_argument("asset_root", type=Path)
parser.add_argument("output", type=Path)
args = parser.parse_args()
result = build_curriculum(args.workbook, args.asset_root)
args.output.parent.mkdir(parents=True, exist_ok=True)
args.output.write_text(
json.dumps(result, ensure_ascii=False, indent=2) + "\n", encoding="utf-8"
)
print(
f"Wrote {result['meta']['week_count']} weeks and "
f"{result['meta']['song_count']} songs to {args.output}"
)
if __name__ == "__main__":
main()
+37
View File
@@ -0,0 +1,37 @@
#!/bin/zsh
# Keep the local LAN server in a detached user session. It intentionally runs
# in the logged-in user's context so it can read the authenticated SMB mount at
# /Volumes/study.
set -eu
session_name='sss50'
project_dir='/Users/optimx/CODE/nas/project_sss'
log_file='/Users/optimx/CODE/nas/project_sss/.local-data/server-tmux.log'
server_command="cd '${project_dir}' && while true; do env ASSET_ROOT='/Volumes/study/Assets/SSS50' DATA_DIR='${project_dir}/.local-data' PORT=8787 PYTHONUNBUFFERED=1 /usr/bin/python3 app.py >> '${log_file}' 2>&1; sleep 2; done"
case "${1:-start}" in
start)
if tmux has-session -t "${session_name}" 2>/dev/null; then
echo "SSS server is already running in tmux session: ${session_name}"
else
tmux new-session -d -s "${session_name}" "${server_command}"
echo "SSS server started: http://127.0.0.1:8787"
fi
;;
status)
tmux has-session -t "${session_name}"
curl -fsS http://127.0.0.1:8787/api/health
;;
logs)
tail -n "${2:-80}" "${log_file}"
;;
stop)
tmux kill-session -t "${session_name}"
echo "SSS server stopped"
;;
*)
echo "Usage: $0 {start|status|logs|stop}" >&2
exit 2
;;
esac