Advertisement
Guest User

Untitled

a guest
Jun 19th, 2017
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.06 KB | None | 0 0
  1. #!/usr/bin/python
  2. import MySQLdb
  3. import getpass
  4.  
  5. connection=MySQLdb.connect("localhost","amstan",getpass.getpass("enter the db password: "),"contest")
  6. cursor=connection.cursor()
  7.  
  8. def query(*args):
  9.         print args
  10.         cursor.execute(*args)
  11.  
  12. while True:
  13.         orgname=raw_input("New organization name: ")                                                                                                                                                                            
  14.         if orgname=="":                                                                                                                                                                                                        
  15.                 break                                                                                                                                                                                                          
  16.                                                                                                                                                                                                                                
  17.         query("""insert into organizations (name) VALUES (%s);""",(orgname,))                                                                                                                                                  
  18.         query("""select * from organizations where name = %s;""",(orgname,))                                                                                                                                                    
  19.         orgid=int(cursor.fetchone()[0])                                                                                                                                                                                        
  20.         print "org_id = %s" % (orgid,)                                                                                                                                                                                          
  21.                                                                                                                                                                                                                                
  22.         while True:                                                                                                                                                                                                            
  23.                 username=raw_input("Username to be added to the group: ")                                                                                                                                                      
  24.                 if username=="":                                                                                                                                                                                                
  25.                         break
  26.  
  27.                 query("update users SET org_id = %s WHERE username = %s;",(orgid,username))
  28.  
  29. connection.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement