Phase 1 - Analytics y Reportes: - PostMetrics and AnalyticsReport models for tracking engagement - Analytics service with dashboard stats, top posts, optimal times - 8 API endpoints at /api/analytics/* - Interactive dashboard with Chart.js charts - Celery tasks for metrics fetch (15min) and weekly reports Phase 2 - Integración Odoo: - Lead and OdooSyncLog models for CRM integration - Odoo fields added to Product and Service models - XML-RPC service for bidirectional sync - Lead management API at /api/leads/* - Leads dashboard template - Celery tasks for product/service sync and lead export Phase 3 - A/B Testing y Recycling: - ABTest, ABTestVariant, RecycledPost models - Statistical winner analysis using chi-square test - Content recycling with engagement-based scoring - APIs at /api/ab-tests/* and /api/recycling/* - Automated test evaluation and content recycling tasks Phase 4 - Thread Series y Templates: - ThreadSeries and ThreadPost models for multi-post threads - AI-powered thread generation - Enhanced ImageTemplate with HTML template support - APIs at /api/threads/* and /api/templates/* - Thread scheduling with reply chain support Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
99 lines
3.6 KiB
Python
99 lines
3.6 KiB
Python
"""
|
|
Social Media Automation - Consultoría AS
|
|
=========================================
|
|
Sistema automatizado para la creación y publicación de contenido
|
|
en redes sociales (X, Threads, Instagram, Facebook).
|
|
"""
|
|
|
|
from contextlib import asynccontextmanager
|
|
|
|
from fastapi import FastAPI
|
|
from fastapi.staticfiles import StaticFiles
|
|
from fastapi.middleware.cors import CORSMiddleware
|
|
|
|
from app.api.routes import posts, products, services, calendar, dashboard, interactions, auth, publish, generate, notifications, analytics, odoo, leads, ab_testing, recycling, threads, image_templates
|
|
from app.core.config import settings
|
|
from app.core.database import engine
|
|
from app.models import Base
|
|
|
|
|
|
@asynccontextmanager
|
|
async def lifespan(app: FastAPI):
|
|
"""Lifecycle manager - crea tablas al iniciar si hay conexión a BD."""
|
|
try:
|
|
Base.metadata.create_all(bind=engine)
|
|
except Exception as e:
|
|
print(f"⚠️ No se pudo conectar a BD: {e}")
|
|
print(" La app funcionará pero sin persistencia hasta configurar BD")
|
|
yield
|
|
|
|
# Inicializar aplicación FastAPI
|
|
app = FastAPI(
|
|
title="Social Media Automation",
|
|
description="Sistema de automatización de redes sociales para Consultoría AS",
|
|
version="1.0.0",
|
|
docs_url="/api/docs",
|
|
redoc_url="/api/redoc",
|
|
lifespan=lifespan,
|
|
)
|
|
|
|
# Configurar CORS
|
|
app.add_middleware(
|
|
CORSMiddleware,
|
|
allow_origins=["*"], # En producción, especificar dominios
|
|
allow_credentials=True,
|
|
allow_methods=["*"],
|
|
allow_headers=["*"],
|
|
)
|
|
|
|
# Montar archivos estáticos
|
|
app.mount("/static", StaticFiles(directory="dashboard/static"), name="static")
|
|
|
|
# Montar directorio de uploads para imágenes públicas
|
|
import os
|
|
os.makedirs("uploads/images", exist_ok=True)
|
|
app.mount("/uploads", StaticFiles(directory="uploads"), name="uploads")
|
|
|
|
# Registrar rutas
|
|
app.include_router(auth.router, prefix="", tags=["Auth"])
|
|
app.include_router(dashboard.router, prefix="", tags=["Dashboard"])
|
|
app.include_router(posts.router, prefix="/api/posts", tags=["Posts"])
|
|
app.include_router(products.router, prefix="/api/products", tags=["Products"])
|
|
app.include_router(services.router, prefix="/api/services", tags=["Services"])
|
|
app.include_router(calendar.router, prefix="/api/calendar", tags=["Calendar"])
|
|
app.include_router(interactions.router, prefix="/api/interactions", tags=["Interactions"])
|
|
app.include_router(publish.router, prefix="/api/publish", tags=["Publish"])
|
|
app.include_router(generate.router, prefix="/api/generate", tags=["AI Generation"])
|
|
app.include_router(notifications.router, prefix="/api/notifications", tags=["Notifications"])
|
|
app.include_router(analytics.router, prefix="/api/analytics", tags=["Analytics"])
|
|
app.include_router(odoo.router, prefix="/api/odoo", tags=["Odoo"])
|
|
app.include_router(leads.router, prefix="/api/leads", tags=["Leads"])
|
|
app.include_router(ab_testing.router, prefix="/api/ab-tests", tags=["A/B Testing"])
|
|
app.include_router(recycling.router, prefix="/api/recycling", tags=["Recycling"])
|
|
app.include_router(threads.router, prefix="/api/threads", tags=["Thread Series"])
|
|
app.include_router(image_templates.router, prefix="/api/templates", tags=["Image Templates"])
|
|
|
|
|
|
@app.get("/api/health")
|
|
async def health_check():
|
|
"""Verificar estado del sistema."""
|
|
return {
|
|
"status": "healthy",
|
|
"app": settings.APP_NAME,
|
|
"version": "1.0.0"
|
|
}
|
|
|
|
|
|
@app.get("/api/stats")
|
|
async def get_stats():
|
|
"""Obtener estadísticas generales del sistema."""
|
|
# TODO: Implementar estadísticas reales desde la BD
|
|
return {
|
|
"posts_today": 0,
|
|
"posts_week": 0,
|
|
"posts_month": 0,
|
|
"pending_approval": 0,
|
|
"scheduled": 0,
|
|
"interactions_pending": 0
|
|
}
|