Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Populating invoice table
#!/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
You can’t perform that action at this time.