File size: 726 Bytes
135f6a8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
import sqlite3

class NewsDatabase:
    def __init__(self, db_path):
        self.conn = sqlite3.connect(db_path)
        self.init_db()
    def init_db(self):
        c = self.conn.cursor()
        c.execute('''CREATE TABLE IF NOT EXISTS alerts (timestamp TEXT, ticker TEXT, headline TEXT, summary TEXT, sentiment REAL, impact_keywords TEXT, urgency REAL)''')
        self.conn.commit()
    def save_alert(self, alert):
        c = self.conn.cursor()
        c.execute('''INSERT INTO alerts VALUES (?,?,?,?,?,?,?)''', (
            alert['timestamp'], alert['ticker'], alert['headline'], alert['summary'],
            alert['sentiment'], alert['impact_keywords'], alert['urgency_score']
        ))
        self.conn.commit()