import os, requests, time
G2 = os.environ["G2_API_KEY"]
MV = os.environ["MAVERA_API_KEY"]
G2_H = {"Authorization": f"Token token={G2}", "Content-Type": "application/vnd.api+json"}
MV_H = {"Authorization": f"Bearer {MV}", "Content-Type": "application/json"}
# 1. Pull reviews with recommendations
reviews = []
page = 1
while len(reviews) < 200:
r = requests.get(f"https://data.g2.com/api/v1/survey-responses",
headers=G2_H, params={"page[size]": 50, "page[number]": page})
if r.status_code == 429:
time.sleep(1); continue
r.raise_for_status()
data = r.json().get("data", [])
if not data: break
reviews.extend(data)
page += 1
time.sleep(0.1)
# 2. Extract high-rating recommendations
quotes = []
for rev in reviews:
attrs = rev.get("attributes", {})
if attrs.get("star_rating", 0) < 4:
continue
for key, val in attrs.get("comment_answers", {}).items():
text = val if isinstance(val, str) else val.get("text", "")
if ("recommend" in key.lower() or "love" in key.lower()) and len(text) > 30:
quotes.append({
"text": text[:300],
"role": attrs.get("title", "User"),
"industry": attrs.get("industry", "Technology"),
"company_size": attrs.get("company_size", "Mid-market"),
"star": attrs.get("star_rating", 5),
})
# 3. Generate social proof assets
quote_block = "\n\n".join(
f'"{q["text"]}" — {q["role"]}, {q["industry"]}, {q["company_size"]}'
for q in quotes[:15]
)
gen = requests.post(f"https://app.mavera.io/api/v1/generations",
headers=MV_H,
json={
"prompt": f"""Using these real G2 reviewer quotes, generate:
1. Five testimonial card headlines (15 words max each)
2. Three case study header lines pairing the quote with a metric
3. Five email proof-point bullets for a nurture sequence
4. Three social media post variants featuring quotes
QUOTES:
{quote_block}
Rules:
- Keep quotes verbatim or clearly attributed
- Pair quotes with role/industry for credibility
- Focus on outcomes and specificity""",
}).json()
print("=== Social Proof Assets ===")
print(gen.get("output", gen.get("content", gen.get("text", "")))[:1500])