27 lines
916 B
Python
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() |