mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-07-08 22:22:17 +02:00
feat(capabilities): wire web.scrape to proprietary crawler
This commit is contained in:
parent
bbd81bcc99
commit
6679fda662
1 changed files with 34 additions and 0 deletions
34
surfsense_backend/app/capabilities/web/scrape/executor.py
Normal file
34
surfsense_backend/app/capabilities/web/scrape/executor.py
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
"""``web.scrape`` executor: fetch each URL in the array → cleaned rows."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from app.capabilities.types import Executor
|
||||
from app.capabilities.web.scrape.schemas import ScrapeInput, ScrapeOutput, ScrapeRow
|
||||
from app.proprietary.web_crawler import (
|
||||
CrawlOutcome,
|
||||
CrawlOutcomeStatus,
|
||||
WebCrawlerConnector,
|
||||
)
|
||||
|
||||
|
||||
def build_scrape_executor(engine: WebCrawlerConnector | None = None) -> Executor:
|
||||
"""Bind the executor to a fetch engine (defaults to the proprietary crawler)."""
|
||||
engine = engine or WebCrawlerConnector()
|
||||
|
||||
async def execute(payload: ScrapeInput) -> ScrapeOutput:
|
||||
rows = [_to_row(url, await engine.crawl_url(url)) for url in payload.urls]
|
||||
return ScrapeOutput(rows=rows)
|
||||
|
||||
return execute
|
||||
|
||||
|
||||
def _to_row(url: str, outcome: CrawlOutcome) -> ScrapeRow:
|
||||
if outcome.status is CrawlOutcomeStatus.SUCCESS and outcome.result:
|
||||
return ScrapeRow(
|
||||
url=url,
|
||||
status="success",
|
||||
content=outcome.result.get("content"),
|
||||
metadata=outcome.result.get("metadata"),
|
||||
)
|
||||
status = "empty" if outcome.status is CrawlOutcomeStatus.EMPTY else "failed"
|
||||
return ScrapeRow(url=url, status=status, error=outcome.error)
|
||||
Loading…
Add table
Add a link
Reference in a new issue