Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import MySQLdb
- from sys import argv as sa
- # user arguments here (can set static)
- global dbname
- global project
- global infile
- global ipadr
- global uname
- global pword
- try:
- try:
- dbname=sa[1]
- except Exception as e:
- print """Please supply a [database] name, even if it exists already ..."""
- try:
- project=sa[2]
- except Exception as e:
- print e
- print """Please supply a [table] name here"""
- try:
- infile=sa[3]
- except Exception as e:
- print e
- print """Please supply the [file] to upload here"""
- try:
- ipadr=sa[4]
- except Exception as e:
- print e
- print """Please give an [IP] here for the mysql instance"""
- try:
- uname=sa[5]
- except Exception as e:
- print e
- print """Please supply a [username] here for the mysql instance"""
- try:
- pword=sa[6]
- except Exception as e:
- print e
- print """Please supply a [password] for the mysql instance"""
- except Exception as e:
- exit()
- def conset():
- global db
- global cur
- db = MySQLdb.connect(host=ipadr, user=uname, password=pword)
- cur = db.cursor()
- def docommit():
- db.commit()
- cur.close()
- def redres(query):
- cur.execute(query)
- result=cur.fetchall()
- for row in result:
- print row
- def usedb():
- try:
- query="use "+dbname
- redres(query)
- except Exception as e:
- print e
- pass
- def credb():
- try:
- conset()
- query="create database "+dbname+";"
- redres(query)
- usedb()
- except Exception as e:
- print e
- usedb()
- # make the db, dont care if it exists;
- def creta():
- try:
- query='CREATE TABLE '+str(project)+' (id INT NOT NULL AUTO_INCREMENT,email blob NOT NULL,user blob NOT NULL,domain blob NOT NULL,password blob NOT NULL,PRIMARY KEY (id));'
- redres(query)
- except Exception as e:
- print e
- pass
- # alter the table, dont care if its alredy set
- def alta():
- try:
- query='ALTER TABLE '+str(project)+' AUTO_INCREMENT = 1;'
- redres(query)
- except Exception as e:
- print e
- pass
- # push the file up
- def fileup():
- try:
- credb()
- creta()
- alta()
- query='LOAD DATA LOCAL INFILE "'+infile+'" INTO TABLE '+str(project)+' FIELDS TERMINATED BY ":" (email, user, domain, password);'
- redres(query)
- docommit()
- except Exception as e:
- print e
- pass
- fileup()
- print "Finished"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement