Skip to content

Instantly share code, notes, and snippets.

@Somsubhra
Last active December 25, 2015 12:08
Show Gist options
  • Select an option

  • Save Somsubhra/6973770 to your computer and use it in GitHub Desktop.

Select an option

Save Somsubhra/6973770 to your computer and use it in GitHub Desktop.
SQL Data Feeder
from random import randint
def main():
f = open('script.sql', 'a')
gen = ['m', 'f']
blood = ['A+', 'A-', 'B+', 'B-', 'AB+', 'AB-', 'O+', 'O-']
organs = ['kidney', 'liver', 'heart', 'eye', 'lung', 'pancreas', 'intestine', 'skin', 'joint', 'face']
type = {'eye': 'other', 'heart':'cardiac', 'kidney':'other', 'liver':'other', 'lung':'other', 'pancreas': 'other', 'intestine': 'other', 'skin':'skin', 'joint': 'cartilage', 'face': 'skin'}
for i in range(100):
f.write("INSERT INTO donor(donor_id, name, age, gen, location, email, phone, password, bg) VALUES("+str(i)+",name"+str(i)+","+str(randint(10,80))+","+gen[randint(0,1)]+",location"+str(i)+","+str(i)+"@example.com"+","+str(randint(10000000, 99999999))+",password"+str(i)+","+blood[randint(0,7)]+");\n")
f.write("INSERT INTO recipient(recipient_id, name, age, gen, location, email, phone, password, bg) VALUES("+str(i)+",name"+str(i)+","+str(randint(10,80))+","+gen[randint(0,1)]+",location"+str(i)+","+str(i)+"@example.com"+","+str(randint(10000000, 99999999))+",password"+str(i)+","+blood[randint(0,7)]+");\n")
f.write("INSERT INTO organ(organ_id, name) VALUES("+str(i)+","+organs[randint(0,9)]+");\n")
organ_entry = organs[randint(0, 9)]
f.write("INSERT INTO organ_category(name, type) VALUES("+organ_entry+","+type[organ_entry]+");\n")
f.write("INSERT INTO doctor(doctor_id, name, phone, location, email, password) VALUES("+str(i)+",name"+str(i)+","+str(randint(10000000, 99999999))+",location"+str(i)+","+str(i)+"@example.com"+",password"+str(i)+");\n")
f.write("INSERT INTO procedure(proc_id, date, cost, duration, donor_id, recipient_id, admin_id, hospital_id, organ_id) VALUES("+str(i)+","+str(randint(1,28))+"/"+str(randint(1,12))+"/"+str(randint(1980,2012))+","+str(randint(100, 1000))+","+str(randint(1, 24))+","+str(randint(1,100))+","+str(randint(1,100))+","+str(randint(1,100))+","+str(randint(1,100))+","+str(randint(1,100))+");\n")
f.write("INSERT INTO procedure-test(proc_id,test_id) VALUES("+str(randint(1,100))+","+str(randint(1,100))+");\n")
f.write("INSERT INTO procedure-doctor(proc_id,doctor_id) VALUES("+str(randint(1,100))+","+str(randint(1,100))+");\n")
f.write("INSERT INTO test_rate(name,cost) VALUES(name"+str(i)+","+str(randint(100,1000))+");\n")
f.write("INSERT INTO test(test_id,name result) VALUES("+str(i)+",name"+str(i)+",name"+str(i)+");\n")
f.write("INSERT INTO admin(admin_id,name,phone,email,password) VALUES("+str(i)+",name"+str(i)+","+str(randint(10000000,99999999))+","+str(i)+"@example.com"+",password"+str(i)+");\n")
f.write("INSERT INTO hospital-doctor(doctor_id,hospital_id,since) VALUES("+str(randint(1,100))+","+str(randint(1,100))+",name"+str(i)+","+str(randint(1,28))+"/"+str(randint(1,12))+"/"+str(randint(1980,2012))+");\n")
f.write("INSERT INTO hospital_contact(hospital_id,phone) VALUES("+str(i)+","+str(randint(10000000,99999999))+");\n")
f.write("INSERT INTO hospital(hospital_id,name,location,email) VALUES("+str(i)+",name"+str(i)+",address"+str(i)+","+str(i)+"@example.com"+");\n")
f.write("INSERT INTO relative(donor_id,name,email) VALUES("+str(i)+",name"+str(i)+","+str(i)+"@example.com"+");\n")
f.write("INSERT INTO test(donor_id,email,phone,password) VALUES("+str(i)+","+str(i)+"@example.com"+","+str(randint(10000000,99999999))+","+",password"+str(i)+");\n")
f.close()
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment