File size: 1,987 Bytes
a74b879 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 | 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()
|