NLP_genAI_final / agents /alertcoordinator.py
irebmann's picture
Initial upload: local files to Hugging Face repo
135f6a8
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)