Created
December 19, 2018 19:31
-
-
Save dontstopbelieveing/3c42338c8f5c756a526ab2f7bef5525e to your computer and use it in GitHub Desktop.
Populating invoice table
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import random | |
from datetime import datetime | |
import MySQLdb as mysql | |
host = | |
user = | |
password = | |
db = | |
port = | |
data={} | |
for y in range (1000): | |
db = mysql.connect(host=host, user=user, passwd=password, db=db, port=port) | |
cursor = db.cursor() | |
for x in range (1000): | |
data["invoice_num"]=random.randint(1,1000000000) | |
data["stockcode"]=random.randint(1,1000000) | |
data['price']=(random.randint(100,1000000))/100 | |
created_date=datetime(random.randint(2010,2018),random.randint(1,12),random.randint(1,28),random.randint(0,23),random.randint(0,59)) | |
data['invoice_date']=str(created_date) | |
qry = "INSERT INTO invoice (invoice_num, stockcode, price, invoice_date) values (%s, %s, %s, %s)" | |
cursor.execute(qry,(data["invoice_num"], data["stockcode"],data['price'],data['invoice_date'])) | |
print "Inserted "+ str(y*x) +" rows" | |
db.commit() | |
db.close() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment