Advertisement
Guest User

Python script to generate product.db

a guest
Mar 15th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.41 KB | None | 0 0
  1. import sqlite3
  2. import random
  3.  
  4. from datetime import datetime
  5.  
  6. db = sqlite3.connect('product.db')
  7. c = db.cursor()
  8. c.execute('PRAGMA journal_mode=WAL;')
  9. c.execute('PRAGMA synchronous=NORMAL;')
  10.  
  11. c.execute('CREATE VIRTUAL TABLE product USING fts4(itemid, sku, name, slug, desc, d_upload, d_update, spec);')
  12.  
  13. sku = ['kwj132123', 'asdsadsad', '123123123', 'ssad12213', '']
  14. name = 'item'
  15. desc = 'This item is so good'
  16. color = ['red', 'pink', 'blue', 'green', 'pale red']
  17. size = ['us6', 'us7', 'us8', 'us9', 'us10', 'us1']
  18. brand = ['vans', 'nike', 'reebok', 'addidas', 'puma', 'new balance', 'asics']
  19. category = 'shoes'
  20. gender = ['boy', 'girl', 'men', 'women']
  21. age = ['kids', 'toddler', 'adult']
  22. for i in range(1, 100001):
  23.     clr = random.choice(color)
  24.     siz = random.choice(size)
  25.     brd = random.choice(brand)
  26.     gnd = random.choice(gender)
  27.     age = random.choice(age)
  28.     specification = ''
  29.     specification += 'color:' + clr + ' '
  30.     specification += 'size:' + siz + ' '
  31.     specification += 'brand:' + brd + ' '
  32.     specification += 'gender:' + gnd + ' '
  33.     specification += 'age:' + age
  34.     now = str(datetime.now())
  35.     if i == 100000:
  36.         specification += ' ' + 'coba:' + 'berhasil'
  37.     data = (str(i), random.choice(sku), name + str(i), name + '-{}'.format(str(i)), desc, now, now, specification)
  38.     c.execute('INSERT INTO product VALUES (?, ?, ?, ?, ?, ?, ?, ?)', data)
  39. db.commit()
  40. db.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement