File size: 981 Bytes
135f6a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
from datetime import datetime

class AlertCoordinatorAgent:
    def __init__(self, config, database):
        self.config = config
        self.db = database

    def process_alerts(self, analyzed):
        for article in analyzed:
            keywords = [k for k in self.config.IMPACT_KEYWORDS if k in article.get('headline','').lower()]
            urgency = len(keywords) * 0.2 + abs(article.get('sentiment',0)) * 0.3
            if urgency > 0.5:  # Threshold, adjust as needed
                alert = {
                    'timestamp': datetime.now().isoformat(),
                    'ticker': article.get('symbol',''),
                    'headline': article.get('headline',''),
                    'summary': article.get('summary',''),
                    'sentiment': article['sentiment'],
                    'impact_keywords': ','.join(keywords),
                    'urgency_score': round(min(urgency, 1.0),2)
                }
                self.db.save_alert(alert)