import os, requests, time
# --- Auth setup same as Job 1 ---
SUB = "marketing"
BRAND = "B2B marketing analytics platform. Audience: Marketing directors/VPs. Tone: Data-driven, practical, contrarian."
# 1. Rising posts
rising = [p["data"] for p in requests.get(f"{RD}/r/{SUB}/rising",
headers=RD_H, params={"limit": 20, "raw_json": 1}).json()["data"]["children"]]
# 2. Brand alignment via Mave
aligned = []
for post in rising:
check = requests.post(f"{MV_BASE}/mave/chat", headers=MV_H, json={
"message": f"Evaluate trend for brand alignment (score 1-10).\n\nTREND: {post['title']}\nCONTEXT: {post.get('selftext','')[:300]}\nSUBREDDIT: /r/{SUB} | Score: {post.get('score',0)}\n\nBRAND: {BRAND}\n\nIf 7+: suggest angle + format. Estimate trend velocity."
}).json()
content = check.get("content", "")
lines = [l for l in content.split("\n") if "/10" in l or "score" in l.lower()]
try: score = int("".join(c for c in (lines[0] if lines else "0") if c.isdigit())[:2])
except: score = 0
if score >= 7:
aligned.append({"title": post["title"], "score": post.get("score",0), "alignment": score, "angle": content[:300]})
time.sleep(0.5)
print(f"Evaluated: {len(rising)} | Aligned: {len(aligned)}")
# 3. Generate content
for trend in aligned[:5]:
gen = requests.post(f"{MV_BASE}/generations", headers=MV_H, json={
"prompt": f"Write a LinkedIn article (600-800 words) based on:\n\nTREND: {trend['title']}\nANGLE: {trend['angle'][:200]}\n\nHook: Open with Reddit insight. Body: Data + frameworks. CTA: Free trial. Tone: data-driven, contrarian.",
}).json()
print(f"\n{'='*50}\nTREND: {trend['title']} | Alignment: {trend['alignment']}/10")
print(gen.get("output", gen.get("content", ""))[:500])