Files
gauvainboiche 3315cb2336 feat: Semaine 8
2026-05-11 09:25:19 +02:00

41 lines
1.1 KiB
Python

from dataclasses import dataclass
from domain.matcher import MatchingService
from domain.entities import Alert
from ports.outbound.article_source_protocol import ArticleSource
from ports.outbound.notifier_protocol import Notifier
@dataclass
class WatchCycleResult:
processed: int
alerts_sent: int
class RunWatchCycleUsecase:
def __init__(
self,
source: ArticleSource,
notifier: Notifier,
matcher: MatchingService
):
self.source = source
self.notifier = notifier
self.matcher = matcher
def execute(self, keywords: list[str]):
articles = self.source.fetch_articles()
alerts_sent = 0
for article in articles:
matched = self.matcher.find_match(article, keywords)
if matched:
alert = Alert(
article= article,
matched_keywords=matched
)
self.notifier.send_alert(alert)
alerts_sent += 1
return WatchCycleResult(
processed=len(articles),
alerts_sent=alerts_sent
)