import os, requests, time
LI = os.environ["LINKEDIN_ACCESS_TOKEN"]
MV = os.environ["MAVERA_API_KEY"]
LI_BASE = "https://api.linkedin.com/rest"
MV_BASE = "https://app.mavera.io/api/v1"
LI_H = {
"Authorization": f"Bearer {LI}",
"Content-Type": "application/json",
"LinkedIn-Version": "202401",
"X-Restli-Protocol-Version": "2.0.0",
}
MV_H = {"Authorization": f"Bearer {MV}", "Content-Type": "application/json"}
# 1. Post a job
job_posting = {
"integrationContext": "urn:li:organization:12345",
"jobPostingOperationType": "CREATE",
"title": "Senior Backend Engineer",
"description": {
"text": (
"We're looking for a Senior Backend Engineer to join our platform team. "
"You'll design and build APIs that serve 10M+ requests/day, mentor junior engineers, "
"and drive architecture decisions. Stack: Python, Go, PostgreSQL, Kubernetes. "
"5+ years experience required. Competitive salary, equity, and fully remote."
),
},
"location": "San Francisco, CA",
"listedAt": int(time.time() * 1000),
"jobPostingStatus": "LISTED",
}
post_resp = requests.post(f"{LI_BASE}/simpleJobPostings",
headers=LI_H, json=job_posting)
post_resp.raise_for_status()
job_id = post_resp.headers.get("X-RestLi-Id", "unknown")
print(f"Posted job: {job_id}")
# 2. Wait for data to accumulate (in production, run this days later)
time.sleep(2)
# 3. Simulate performance metrics (replace with real analytics in production)
metrics = {
"views": 1240,
"applies": 31,
"apply_rate": 2.5,
"benchmark_apply_rate": 5.0,
}
# 4. If underperforming, test with Focus Group
if metrics["apply_rate"] < metrics["benchmark_apply_rate"]:
print(f"Apply rate {metrics['apply_rate']}% below benchmark {metrics['benchmark_apply_rate']}%")
candidate_personas = []
for archetype in [
{"name": "Passive Staff Engineer", "desc": "10+ yrs, employed at FAANG. Only moves for exceptional roles."},
{"name": "Active Senior IC", "desc": "5-7 yrs, actively looking. Applying to 10+ roles. Values clarity."},
{"name": "Career Transitioner", "desc": "Backend dev moving from enterprise to startup. Evaluating risk."},
]:
p = requests.post(f"{MV_BASE}/personas", headers=MV_H, json={
"name": f"LI Talent: {archetype['name']}",
"description": archetype["desc"],
}).json()
candidate_personas.append(p["id"])
time.sleep(0.2)
fg = requests.post(f"{MV_BASE}/focus-groups", headers=MV_H, json={
"name": f"Job Posting Review: {job_posting['title']}",
"persona_ids": candidate_personas,
"questions": [
{"type": "likert", "text": "Rate appeal of this posting (1=skip, 5=apply now)", "scale": 5},
"What about this posting makes you hesitant to apply?",
"What information is missing that you'd need before applying?",
"How does this compare to other Senior Backend Engineer postings you've seen?",
"Rewrite the first two sentences to make them more compelling for YOU.",
],
"context": job_posting["description"]["text"],
"responses_per_persona": 3,
}).json()
for _ in range(20):
time.sleep(5)
fg_data = requests.get(f"{MV_BASE}/focus-groups/{fg['id']}", headers=MV_H).json()
if fg_data.get("status") == "completed":
break
feedback_summary = "\n".join(
f"- [{r.get('persona_id','?')[:8]}] {r.get('question','')[:40]}: {r.get('answer','')[:200]}"
for r in fg_data.get("responses", [])
)
# 5. Generate improved description
gen = requests.post(f"{MV_BASE}/generations", headers=MV_H, json={
"prompt": (
f"Rewrite this job posting based on candidate feedback.\n\n"
f"ORIGINAL:\n{job_posting['description']['text']}\n\n"
f"FEEDBACK:\n{feedback_summary}\n\n"
f"REQUIREMENTS:\n"
f"- Address every concern raised\n"
f"- Keep under 300 words\n"
f"- Lead with impact, not requirements\n"
f"- Include salary range and specific benefits\n"
f"- Make the first sentence irresistible"
),
}).json()
improved = gen.get("output", gen.get("content", gen.get("text", "")))
print(f"\n=== Improved Description ===\n{improved[:800]}")
# 6. Update the posting (in production)
# job_posting["description"]["text"] = improved
# job_posting["jobPostingOperationType"] = "UPDATE"
# requests.post(f"{LI_BASE}/simpleJobPostings", headers=LI_H, json=job_posting)