← back to Wallco Ai

scripts/curator-excluded-ids.py

34 lines

#!/usr/bin/env python3
"""Print comma-separated design ids whose LATEST cactus-curator decision is a
takedown ('unpublish' or 'bad'). The drunk-animals publish loop excludes these
so it never re-publishes a design the curator deliberately took down via
/admin/cactus-curator (POST /api/cactus-decision/bulk). A later 'live' decision
(re-publish via the UI) overrides the takedown — latest line wins.

Reads data/cactus-decisions.jsonl (append-only {ts,id,action}). Prints '-1' when
empty so `AND id NOT IN (-1)` stays valid SQL.
"""
import json, os

F = os.path.join(os.path.dirname(__file__), '..', 'data', 'cactus-decisions.jsonl')
latest = {}
try:
    with open(F) as fh:
        for line in fh:
            line = line.strip()
            if not line:
                continue
            try:
                d = json.loads(line)
            except Exception:
                continue
            i, a = d.get('id'), d.get('action')
            if i is None or not a:
                continue
            latest[i] = a  # append-only → last line for an id is its current decision
except FileNotFoundError:
    pass

excl = [str(i) for i, a in latest.items() if a in ('unpublish', 'bad')]
print(','.join(excl) if excl else '-1')