feat: Semaine 8
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
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
|
||||
)
|
||||
Reference in New Issue
Block a user