← back to Contact Mailer Ideas

build-pitch-tasks.py

87 lines

#!/usr/bin/env python3
"""Build TSV of pitch-render tasks across all batches.
Output cols: batch \t idx \t name \t score \t headline \t script
"""
import json, os, glob
from collections import defaultdict

JSONL = os.path.expanduser("~/.claude/skills/idea-loop/data/ideas.jsonl")
BATCHES_DIR = os.path.expanduser("~/Projects/contact-mailer-ideas/batches")

ideas_by_batch = {}
for f in sorted(glob.glob(os.path.join(BATCHES_DIR, "*.json"))):
    d = json.load(open(f))
    ideas_by_batch[d["batch"]] = d

latest_scored = {}
latest_marketing = {}
for line in open(JSONL):
    try:
        t = json.loads(line)
    except Exception:
        continue
    key = (t.get("batch"), t.get("idx"))
    if t.get("scores"):
        if key not in latest_scored or t.get("tick", 0) > latest_scored[key].get("tick", 0):
            latest_scored[key] = t
    if t.get("marketing"):
        if key not in latest_marketing or t.get("tick", 0) > latest_marketing[key].get("tick", 0):
            latest_marketing[key] = t

def clean(s):
    return (s or "").replace("\t", " ").replace("\n", " ").replace("\r", " ").strip()

for batch_slug, doc in ideas_by_batch.items():
    for idea in doc.get("ideas", []):
        idx = idea["idx"]
        name = idea["name"]
        st = latest_scored.get((batch_slug, idx))
        mkt = latest_marketing.get((batch_slug, idx))

        headline = clean(idea.get("headline"))
        if not headline and st:
            headline = clean(st.get("new_headline"))
        if not headline:
            headline = clean(idea.get("angle", ""))

        score = "—"
        if st and st.get("scores"):
            s = st["scores"]
            score = str(s.get("novelty", 0) + s.get("fit", 0) + s.get("feas", 0) + s.get("impact", 0))

        target = clean(idea.get("target"))
        hook = ""
        repeat = ""
        if mkt and mkt.get("marketing"):
            hook = clean(mkt["marketing"].get("hook"))
            repeat = clean(mkt["marketing"].get("repeat"))

        # Build ~70-80 word script
        parts = []
        if target:
            parts.append(f"Here's the market: {target}.")
        else:
            parts.append("This is an underserved market.")
        if hook:
            h = hook.rstrip(".") + "."
            # Strip surrounding quotes
            h = h.strip("'").strip('"')
            parts.append(h)
        else:
            parts.append(f"{name} is the answer.")
        if repeat:
            r = repeat[:240]
            if len(repeat) > 240:
                r = r.rsplit(" ", 1)[0] + "."
            parts.append(r)
        else:
            parts.append("It scales structurally as the customer base grows.")
        parts.append(f"Scored {score} out of 40 on the agentabrams opportunity scale.")

        script = " ".join(parts)
        # Replace any remaining quote chars that might bash-escape badly
        script = script.replace("'", "").replace('"', "")
        script = " ".join(script.split())  # collapse whitespace

        print(f"{batch_slug}\t{idx}\t{name}\t{score}\t{headline}\t{script}")