-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHandleFeedback.py
37 lines (32 loc) · 1.08 KB
/
HandleFeedback.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import sqlite3
from datetime import datetime
# Create or connect to SQLite database
def init_db():
conn = sqlite3.connect("feedback.db") # Creates 'feedback.db' file if it doesn't exist
cursor = conn.cursor()
# Create table if it doesn't exist
cursor.execute('''
CREATE TABLE IF NOT EXISTS feedback (
id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT NOT NULL,
timestamp DATETIME DEFAULT CURRENT_TIMESTAMP,
feedback_text TEXT NOT NULL
)
''')
conn.commit()
conn.close()
# Function to insert feedback into the database
def insert_feedback(username, feedback_text):
try:
conn = sqlite3.connect("feedback.db")
cursor = conn.cursor()
# Insert feedback into table
cursor.execute('''
INSERT INTO feedback (username, feedback_text)
VALUES (?, ?)
''', (username, feedback_text))
conn.commit()
conn.close()
return True
except Exception as e:
print(f"Database error: {e}")