import logging from typing import Optional, List from modules.datamodels.datamodelWeb import ( WebSearchRequest, WebCrawlRequest, WebScrapeRequest, WebSearchActionResult, WebCrawlActionResult, WebScrapeActionResult, ) from modules.interfaces.interfaceWebObjects import WebInterface logger = logging.getLogger(__name__) class WebService: """Centralized Web service providing wrappers around web interface actions. """ def __init__(self, serviceCenter=None) -> None: self.serviceCenter = serviceCenter async def webSearch(self, request: WebSearchRequest) -> WebSearchActionResult: try: web_interface = await WebInterface.create() return await web_interface.search(request) except Exception as e: logger.error(f"Error in webSearch: {str(e)}") raise async def webCrawl(self, request: WebCrawlRequest) -> WebCrawlActionResult: try: web_interface = await WebInterface.create() return await web_interface.crawl(request) except Exception as e: logger.error(f"Error in webCrawl: {str(e)}") raise async def webScrape(self, request: WebScrapeRequest) -> WebScrapeActionResult: try: web_interface = await WebInterface.create() return await web_interface.scrape(request) except Exception as e: logger.error(f"Error in webScrape: {str(e)}") raise