-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrandomly-populate-user-pref-db.py
36 lines (30 loc) · 1.42 KB
/
randomly-populate-user-pref-db.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
import sqlite3
import random
def insertVariableIntoTable(age, spirituality, location, engagement, user_id):
try:
sqliteConnection = sqlite3.connect('Intellivo-app/intellivo_package/intellivoUser.db')
cursor = sqliteConnection.cursor()
print("Connected to SQLite")
sqlite_insert_with_param = """INSERT INTO user_pref (age, spirituality, location, engagement, user_id)
VALUES (?, ?, ?, ?, ?);"""
data_tuple = (age, spirituality, location, engagement, user_id)
cursor.execute(sqlite_insert_with_param, data_tuple)
sqliteConnection.commit()
print("Python Variables inserted successfully into SqliteDb_developers table")
cursor.close()
except sqlite3.Error as error:
print("Failed to insert Python variable into sqlite table", error)
finally:
if (sqliteConnection):
sqliteConnection.close()
print("The SQLite connection is closed")
# adjust the range based on the current ids already in the db
# adn how many user prefs you want to generate
start_idx = int(input('Start Index: '))
num_random = int(input('How many randomly generated users do you want? '))
for i in range(start_idx, start_idx + num_random):
age = random.randrange(4)+1
spirituality = random.randrange(5)+1
location = random.randrange(15)+1
engagement = random.randrange(5)+1
insertVariableIntoTable(age, spirituality, location, engagement, i)