File size: 1,492 Bytes
5f65b18
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import sqlite3
import random
import datetime

# Connect to sqlite
conn = sqlite3.connect('test.db')
cursor = conn.cursor()

# Create table with transaction_date
table = """

CREATE TABLE item (

    item_name VARCHAR(255),

    item_price INT,

    item_quantity INT,

    item_purchase_price INT,

    transaction_date DATE

);

"""
cursor.execute(table)

# Sample item names
item_names = ['Rice', 'Wheat', 'Milk', 'Eggs', 'Butter', 'Salt', 'Sugar', 'Tea', 'Coffee', 'Bread',
              'Flour', 'Oil', 'Chicken', 'Beef', 'Apple', 'Banana', 'Onion', 'Tomato', 'Potato', 'Garlic']

# Generate and insert sample data
for _ in range(500):
    item_name = random.choice(item_names) + f"_{random.randint(1, 1000)}"
    item_price = random.randint(10, 500)
    item_quantity = random.randint(1, 100)
    item_purchase_price = item_price - random.randint(1, 5)

    # Random date in the last 60 days
    transaction_date = datetime.date.today() - datetime.timedelta(days=random.randint(0, 60))

    insert_query = '''

    INSERT INTO item (item_name, item_price, item_quantity, item_purchase_price, transaction_date)

    VALUES (?, ?, ?, ?, ?);

    '''
    cursor.execute(insert_query, (item_name, item_price, item_quantity, item_purchase_price, transaction_date))

# Display data inserted
print("Data Inserted in the table:")
data = cursor.execute('''SELECT * FROM item''')
for row in data:
    print(row)

# Commit and close
conn.commit()
conn.close()