"""Website Automation Service for API layer - orchestrates website creation.""" from typing import Dict, Any, Optional from loguru import logger import os import tempfile import json from fastapi import HTTPException # Import the actual automation service from services.onboarding.website_automation_service import WebsiteAutomationService as CoreAutomationService class WebsiteAutomationService: """API layer service for website automation operations.""" def __init__(self): logger.info("🔄 Initializing WebsiteAutomationService (API layer)...") self.core_service = CoreAutomationService() async def generate_preview_site( self, user_id: str, site_brief: Dict[str, Any], css: str ) -> Dict[str, Any]: """Generate a preview site for the user.""" try: logger.info(f"Generating preview site for user {user_id}") # For preview, we'll create a temporary HTML file # In production, this could be hosted on a preview server preview_html = self._generate_preview_html(site_brief, css) # Save to temporary file (in production, use proper hosting) preview_url = f"/preview/{user_id}/index.html" return { "preview_url": preview_url, "preview_root": f"/preview/{user_id}", "preview_files": ["index.html", "custom.css"], "preview_html": preview_html } except Exception as e: logger.error(f"Failed to generate preview site: {str(e)}") raise HTTPException(status_code=500, detail=f"Preview generation failed: {str(e)}") def _generate_preview_html(self, site_brief: Dict[str, Any], css: str) -> str: """Generate HTML preview from site brief and CSS.""" try: site_data = site_brief.get("site_brief", {}) business_name = site_data.get("business_name", "Your Business") tagline = site_data.get("tagline", "Your tagline here") # Get content plan content_plan = site_brief.get("content_plan", {}) required_pages = content_plan.get("required_pages", []) # Generate HTML html = f"""
{str(e)}
" def _generate_page_content(self, required_pages: list) -> str: """Generate HTML content for pages.""" if not required_pages: return """This is a preview of your new website. The content will be generated based on your business information.
Learn more about your business and what makes you unique.
Discover the services and products you offer to your customers.
Get in touch with you through various contact methods.
{goal}
""" if key_points: page_html += "{point}