Skip to content

Commit

Permalink
Create data_collection.py
Browse files Browse the repository at this point in the history
  • Loading branch information
sv410 authored Oct 9, 2024
1 parent 80402b3 commit f883dc2
Showing 1 changed file with 30 additions and 0 deletions.
30 changes: 30 additions & 0 deletions data_collection.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,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')

0 comments on commit f883dc2

Please sign in to comment.