#!/usr/bin/env python3
"""tvreviewer.com /now-streaming/ weekly refresh — skeleton.

This is the manual-now-automated-later starter. As of 2026-05-08 the page is
hand-curated. When traffic validates the demand, this script becomes the
nightly/weekly refresh engine.

Workflow when activated:
  1. Pull "what's airing this week" from a structured source (TMDB API,
     Watchmode, or scraping JustWatch).
  2. For each candidate, ask Claude (Opus 4.7) to write a one-sentence verdict
     in the existing voice — see VOICE_GUIDE below.
  3. Render index.html from a template.
  4. Diff against last week's published version.
  5. Commit + scp + B2 + verify live.

Today this script is the editorial helper: read the current /now-streaming/
index.html, parse the list of shows, prompt Paul for the new week's slate,
write a draft.

Run:
  python3 refresh.py --draft 2026-05-15
"""
from __future__ import annotations
import argparse
import json
import sys
from datetime import date, timedelta
from pathlib import Path

ROOT = Path(__file__).parent
SLATE_PATH = ROOT / "slate.json"

# === EDITORIAL CONSTANTS ============================================
PLATFORMS = [
    "Apple TV+", "HBO", "Max", "Netflix", "Disney+", "FX",
    "Hulu", "Prime Video", "Paramount+", "Peacock", "AMC+",
]

BADGES = {
    "must":  ("Must Watch",      "rgba(33,200,122,.15)",  "#21c87a"),
    "new":   ("New This Week",   "rgba(201,168,76,.15)",  "#c9a84c"),
    "maybe": ("Worth A Look",    "rgba(168,205,221,.08)", "#c2dce8"),
    "skip":  ("Skip",            "rgba(220,80,90,.12)",   "#f87a85"),
}

VOICE_GUIDE = """\
TVReviewer.com voice notes for one-line verdicts:
- Direct, opinionated, never wishy-washy
- 1-3 short sentences max
- Drop the trailing 'also-recommended' clauses other sites pile on
- Concrete: name what specifically works (an actor, a scene, a structural choice)
- Allow one bolded phrase per verdict for the biggest claim — used sparingly
- Avoid 'gripping', 'compelling', 'must-see' — they signal a press release
- Never describe a show by what it's "like" (no "X meets Y") — describe what it is
"""


def parse_args():
    ap = argparse.ArgumentParser(description="Weekly refresh helper for /now-streaming/")
    ap.add_argument("--draft", help="Generate a draft slate for the given Sunday (YYYY-MM-DD)")
    ap.add_argument("--list-current", action="store_true", help="List shows from the live page")
    ap.add_argument("--with-claude", action="store_true",
                    help="(Future) Use Claude API to draft verdicts. Requires ANTHROPIC_API_KEY env var.")
    return ap.parse_args()


def load_slate():
    if SLATE_PATH.exists():
        return json.loads(SLATE_PATH.read_text(encoding="utf-8"))
    return {"weeks": []}


def list_current():
    slate = load_slate()
    if not slate["weeks"]:
        print("No slate.json yet — first run uses the hand-built page as ground truth.")
        return
    latest = slate["weeks"][-1]
    print(f"Week of {latest['week_of']} — {len(latest['rows'])} shows:")
    for r in latest["rows"]:
        print(f"  [{r['badge']:5s}] {r['platform']:14s} {r['title']}")


def draft_template(week_of: str):
    """Print a fillable JSON template for a new week's slate."""
    template = {
        "week_of": week_of,
        "refreshed": str(date.today()),
        "rows": [
            {
                "platform": "Apple TV+",
                "when": "Returning · Wed",
                "title": "Show Name",
                "title_url": "/reviews/show-slug/",  # internal link if review exists
                "verdict": "One-line verdict in the TVReviewer voice.",
                "badge": "must",  # must, new, maybe, or skip
            },
        ],
        "calendar": [
            {"date": (date.fromisoformat(week_of) + timedelta(days=i)).isoformat(),
             "label": "Event description"} for i in range(0, 14, 3)
        ],
    }
    print(json.dumps(template, indent=2))


def main():
    args = parse_args()
    if args.list_current:
        list_current()
        return 0
    if args.draft:
        draft_template(args.draft)
        return 0
    print(__doc__)
    print("Voice guide:")
    print(VOICE_GUIDE)
    return 0


if __name__ == "__main__":
    sys.exit(main())
