forked from Anjaliavv51/Retro
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdata_collection.py
More file actions
30 lines (26 loc) · 760 Bytes
/
data_collection.py
File metadata and controls
30 lines (26 loc) · 760 Bytes
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
from datetime import datetime
import sqlite3
# Connect to SQLite database
conn = sqlite3.connect('user_data.db')
cursor = conn.cursor()
# Create table
cursor.execute('''
CREATE TABLE IF NOT EXISTS user_interactions (
user_id INTEGER,
item_id INTEGER,
interaction_type TEXT,
timestamp DATETIME
)
''')
# Function to log interaction
def log_interaction(user_id, item_id, interaction_type):
timestamp = datetime.now()
cursor.execute('''
INSERT INTO user_interactions (user_id, item_id, interaction_type, timestamp)
VALUES (?, ?, ?, ?)
''', (user_id, item_id, interaction_type, timestamp))
conn.commit()
# Example usage
log_interaction(1, 101, 'click')
log_interaction(1, 102, 'view')
log_interaction(2, 101, 'purchase')