Added version 4
This commit is contained in:
27
jokes_bot/v4.0/database.py
Normal file
27
jokes_bot/v4.0/database.py
Normal file
@@ -0,0 +1,27 @@
|
||||
# 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()
|
||||
Reference in New Issue
Block a user