last_edit / server /outreach_engine.py
Moharek
Deploy Moharek GEO Platform
a74b879
import os
import time
import requests
from server.db import SessionLocal, Lead, Action
def search_prospects(query: str, job_id: int):
"""Finds potential backlink prospects (blogs/sites) for a niche."""
db = SessionLocal()
try:
# In production: use SerpApi or specialized crawlers
# We simulate finding 3 prospects
mock_prospects = [
{"url": "https://tech-blog-example.com", "email": "admin@tech-blog-example.com"},
{"url": "https://marketing-trends.io", "email": "hello@marketing-trends.io"},
{"url": "https://ai-news-weekly.net", "email": "contact@ai-news-weekly.net"}
]
leads_added = []
for p in mock_prospects:
new_lead = Lead(
job_id=job_id,
url=p['url'],
email=p['email'],
status='found'
)
db.add(new_lead)
db.flush()
leads_added.append(new_lead.id)
# Create an Action for each lead
action_task = f"Send outreach email to {p['url']} for backlink placement."
new_act = Action(
job_id=job_id,
type="outreach",
task=action_task,
priority_score=70, # Steady priority
status='pending'
)
db.add(new_act)
db.commit()
return leads_added
finally:
db.close()
def send_outreach_email(lead_id: int):
"""Mocks sending a personalized AI-generated outreach email."""
db = SessionLocal()
try:
lead = db.query(Lead).filter(Lead.id == lead_id).first()
if not lead: return False
# In production: Use SMTP or SendGrid + AI Template
print(f"Sending automated email to: {lead.email}")
time.sleep(1)
lead.status = 'outreach_sent'
db.commit()
return True
finally:
db.close()