Files
ai6-m3/jokes_bot/v4.0/database.py
2026-01-30 11:47:06 +03:00

27 lines
916 B
Python

# database.py
import sqlite3
conn = sqlite3.connect('jokes.db')
cursor = conn.cursor()
cursor.execute('''CREATE TABLE IF NOT EXISTS jokes (
id INTEGER PRIMARY KEY AUTOINCREMENT,
joke TEXT NOT NULL,
contributor TEXT NOT NULL,
published TEXT NOT NULL,
sentiment_score REAL DEFAULT 0.0,
sentiment_label TEXT DEFAULT '😐 Neutral'
)''')
# Create a new table to store user sentiments for each joke
cursor.execute('''CREATE TABLE IF NOT EXISTS user_sentiments (
id INTEGER PRIMARY KEY AUTOINCREMENT,
joke_id INTEGER NOT NULL,
user_sentiment TEXT CHECK(user_sentiment IN ('up', 'down', 'neutral')) DEFAULT 'neutral',
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
FOREIGN KEY (joke_id) REFERENCES jokes(id) ON DELETE CASCADE
)''')
conn.commit()
print("✅ Database and tables created successfully with AI sentiment columns and user sentiment tracking!")
conn.close()