From f883dc24993976079d045d71b69d3c8da9b841f4 Mon Sep 17 00:00:00 2001 From: srivani vinnakota <164530944+sv410@users.noreply.github.com> Date: Wed, 9 Oct 2024 19:42:56 +0530 Subject: [PATCH] Create data_collection.py --- data_collection.py | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 data_collection.py diff --git a/data_collection.py b/data_collection.py new file mode 100644 index 00000000..33c0e78d --- /dev/null +++ b/data_collection.py @@ -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')