forked from LiveCarta/ContentAutomation
Implemented content upload app with tests and pre-commit hooks
This commit is contained in:
34
src/content_automation/controller.py
Normal file
34
src/content_automation/controller.py
Normal file
@@ -0,0 +1,34 @@
|
||||
from __future__ import annotations
|
||||
|
||||
from content_automation.adapters.storage.base import StorageAdapterBase
|
||||
from content_automation.interfaces import SocialNetworkAdapter
|
||||
from content_automation.settings import AppSettings
|
||||
|
||||
|
||||
class PublishController:
|
||||
"""Coordinates storage lookup and cross-network publishing."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
settings: AppSettings,
|
||||
storage: StorageAdapterBase,
|
||||
social_adapters: dict[str, SocialNetworkAdapter],
|
||||
) -> None:
|
||||
self._settings = settings
|
||||
self._storage = storage
|
||||
self._social_adapters = social_adapters
|
||||
|
||||
def publish(self, relative_path: str, caption: str) -> dict[str, str]:
|
||||
if not self._storage.exists(relative_path):
|
||||
raise FileNotFoundError(
|
||||
f"Media file is not available in storage: {relative_path}"
|
||||
)
|
||||
|
||||
media_url = self._storage.get_public_url(relative_path)
|
||||
result: dict[str, str] = {}
|
||||
for network in self._settings.target_social_networks:
|
||||
adapter = self._social_adapters.get(network)
|
||||
if adapter is None:
|
||||
raise ValueError(f"No adapter configured for network: {network}")
|
||||
result[network] = adapter.post_media(media_url=media_url, caption=caption)
|
||||
return result
|
||||
Reference in New Issue
Block a user