49 lines
1.1 KiB
Python
49 lines
1.1 KiB
Python
#!/usr/bin/env python3
|
|
|
|
import json
|
|
import random
|
|
import sqlite3
|
|
import sys
|
|
|
|
DATABASE = 'db.sqlite3'
|
|
|
|
|
|
def main():
|
|
conn = sqlite3.connect(DATABASE)
|
|
conn.row_factory = sqlite3.Row
|
|
cursor = conn.cursor()
|
|
output = cursor.execute(
|
|
'SELECT user_id FROM users ORDER BY user_id DESC').fetchall()
|
|
existing_ids = [str(dict(row)['user_id']) for row in output]
|
|
|
|
if len(sys.argv) < 2:
|
|
n = 10
|
|
else:
|
|
n = int(sys.argv[1])
|
|
|
|
with open('/usr/share/dict/names', 'r') as name_file:
|
|
names = [row.strip('\n') for row in name_file]
|
|
|
|
for _ in range(n):
|
|
user_id = '1'
|
|
while user_id in existing_ids:
|
|
user_id = str(random.randint(1, 1000000))
|
|
existing_ids.append(user_id)
|
|
|
|
username = random.choice(names)
|
|
|
|
score = str(random.randint(0, 1000))
|
|
|
|
query = \
|
|
'INSERT INTO users (user_id, username, score) VALUES ({}, \'{}\', {})'\
|
|
.format(user_id, username, score)
|
|
|
|
print(query)
|
|
cursor.execute(query)
|
|
|
|
conn.commit()
|
|
conn.close()
|
|
|
|
|
|
if __name__ == '__main__':
|
|
main()
|