import os, requests, time
PG_KEY = os.environ["PERIGON_API_KEY"]
PG_BASE = "https://api.goperigon.com/v1"
MV = os.environ["MAVERA_API_KEY"]
MV_BASE = "https://app.mavera.io/api/v1"
MV_H = {"Authorization": f"Bearer {MV}", "Content-Type": "application/json"}
TOPIC = "fintech"
# 1. Fetch articles with summaries
r = requests.get(f"{PG_BASE}/all", params={
"apiKey": PG_KEY, "q": TOPIC, "sortBy": "date",
"size": 12, "sourceGroup": "top100",
})
r.raise_for_status()
articles = r.json().get("articles", [])
print(f"Fetched {len(articles)} articles for '{TOPIC}'")
# 2. Build digest from summaries
digest_items = []
for a in articles:
summary = a.get("summary", a.get("description", ""))
if not summary:
continue
digest_items.append(
f"**{a.get('title','')}** ({a.get('source',{}).get('name','')})\n{summary[:400]}"
)
digest_text = "\n\n".join(digest_items[:10])
# 3. Create audience personas
AUDIENCES = [
{"name": "C-Suite Executive", "desc": "CEO/CFO at a fintech company. Cares about market trends, regulation, fundraising signals, and strategic positioning. Prefers bullet points, numbers, and bottom-line impact."},
{"name": "Product Manager", "desc": "PM at a fintech startup. Cares about feature trends, user expectations, competitive moves, and technology shifts. Prefers actionable insights with implementation angles."},
{"name": "Finance Student", "desc": "Graduate student studying financial technology. Cares about industry structure, career opportunities, and understanding how concepts connect. Prefers explanations with context."},
]
persona_ids = []
for aud in AUDIENCES:
p = requests.post(f"{MV_BASE}/personas", headers=MV_H, json={
"name": f"Digest: {aud['name']}",
"description": aud["desc"],
}).json()
persona_ids.append({"id": p["id"], "name": aud["name"]})
time.sleep(0.3)
# 4. Generate persona-voiced digest
for persona in persona_ids:
speak = requests.post(f"{MV_BASE}/speak", headers=MV_H, json={
"persona_id": persona["id"],
"input": [
{"role": "system", "content": f"You are a {persona['name']}. Rewrite this news digest in YOUR voice — the way you'd summarize it for peers. 5-7 bullet points. Match your communication style."},
{"role": "user", "content": f"This week's {TOPIC} news:\n\n{digest_text}"},
],
"mode": "interview",
}).json()
print(f"\n{'='*60}\nDIGEST FOR: {persona['name']}\n{'='*60}")
for ex in speak.get("exchanges", speak.get("messages", [])):
if ex.get("role") == "assistant":
print(ex["content"][:600])
time.sleep(0.3)