- Add abstract get_post_metrics() method to BasePublisher - Implement get_post_metrics() in XPublisher using Twitter API v2 - Returns: likes, comments, shares, retweets, quotes, impressions - Implement get_post_metrics() in ThreadsPublisher using Meta Graph API - Implement get_post_metrics() in FacebookPublisher with insights - Implement get_post_metrics() in InstagramPublisher with insights This enables the fetch_post_metrics task to collect engagement data from all platforms, populating the analytics dashboard. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
86 lines
2.1 KiB
Python
86 lines
2.1 KiB
Python
"""
|
|
Clase base para publishers de redes sociales.
|
|
"""
|
|
|
|
from abc import ABC, abstractmethod
|
|
from typing import Optional, List, Dict
|
|
from dataclasses import dataclass
|
|
|
|
|
|
@dataclass
|
|
class PublishResult:
|
|
"""Resultado de una publicación."""
|
|
success: bool
|
|
post_id: Optional[str] = None
|
|
url: Optional[str] = None
|
|
error_message: Optional[str] = None
|
|
|
|
|
|
class BasePublisher(ABC):
|
|
"""Clase base abstracta para publishers."""
|
|
|
|
platform: str = "base"
|
|
|
|
@abstractmethod
|
|
async def publish(
|
|
self,
|
|
content: str,
|
|
image_path: Optional[str] = None
|
|
) -> PublishResult:
|
|
"""Publicar contenido en la plataforma."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
async def publish_thread(
|
|
self,
|
|
posts: List[str],
|
|
images: Optional[List[str]] = None
|
|
) -> PublishResult:
|
|
"""Publicar un hilo de posts."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
async def reply(
|
|
self,
|
|
post_id: str,
|
|
content: str
|
|
) -> PublishResult:
|
|
"""Responder a un post."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
async def like(self, post_id: str) -> bool:
|
|
"""Dar like a un post."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
async def get_mentions(self, since_id: Optional[str] = None) -> List[Dict]:
|
|
"""Obtener menciones recientes."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
async def get_comments(self, post_id: str) -> List[Dict]:
|
|
"""Obtener comentarios de un post."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
async def delete(self, post_id: str) -> bool:
|
|
"""Eliminar un post."""
|
|
pass
|
|
|
|
@abstractmethod
|
|
async def get_post_metrics(self, post_id: str) -> Optional[Dict]:
|
|
"""
|
|
Obtener métricas de un post.
|
|
|
|
Returns:
|
|
Dict con métricas: likes, comments, shares, impressions, etc.
|
|
None si no se pueden obtener
|
|
"""
|
|
pass
|
|
|
|
def validate_content(self, content: str) -> bool:
|
|
"""Validar que el contenido cumple con los límites de la plataforma."""
|
|
# Implementar en subclases según límites específicos
|
|
return True
|