Spaces:
Configuration error
Configuration error
Download src/campaigns.py from Brettapps/Trifecta-Lab: direct link, hf CLI and curl.
- Browser
- Download file 1.68 kB
-
https://huggingface.co/spaces/Brettapps/Trifecta-Lab/resolve/main/src/campaigns.py
- Command line
-
hf download hf://spaces/Brettapps/Trifecta-Lab/src/campaigns.py
-
curl -L -o campaigns.py https://huggingface.co/spaces/Brettapps/Trifecta-Lab/resolve/main/src/campaigns.py
1.68 kB
| """Campaign management module""" | |
| from fastapi import APIRouter | |
| from pydantic import BaseModel | |
| from typing import List, Optional | |
| from datetime import datetime | |
| router = APIRouter(prefix="/campaigns") | |
| class CampaignCreate(BaseModel): | |
| name: str | |
| industry: str | |
| budget: float | |
| channels: List[str] = ["email"] | |
| start_date: Optional[str] = None | |
| class CampaignResponse(BaseModel): | |
| id: int | |
| name: str | |
| status: str | |
| budget: float | |
| leads_targeted: int | |
| created_at: str | |
| _campaigns_db = {} | |
| _next_id = 1 | |
| async def create_campaign(campaign: CampaignCreate): | |
| global _next_id | |
| # Calculate estimated leads | |
| leads_targeted = int(campaign.budget * 0.15) | |
| _campaigns_db[_next_id] = { | |
| "name": campaign.name, | |
| "industry": campaign.industry, | |
| "budget": campaign.budget, | |
| "leads_targeted": leads_targeted, | |
| "status": "running", | |
| "created_at": datetime.utcnow().isoformat() | |
| } | |
| cid = _next_id | |
| _next_id += 1 | |
| return CampaignResponse( | |
| id=cid, | |
| name=campaign.name, | |
| status="running", | |
| budget=campaign.budget, | |
| leads_targeted=leads_targeted, | |
| created_at=datetime.utcnow().isoformat() | |
| ) | |
| async def list_campaigns(): | |
| return [ | |
| CampaignResponse( | |
| id=cid, | |
| name=data["name"], | |
| status=data["status"], | |
| budget=data["budget"], | |
| leads_targeted=data["leads_targeted"], | |
| created_at=data["created_at"] | |
| ) | |
| for cid, data in _campaigns_db.items() | |
| ] |