def importGradesourceNamesInMySQL(mysqlClassId): config = utils.getConfig() g = Gradesource(config['gradesourceLogin'], config['gradesourcePasswd']) infos = g.studentsInfo() db = torndb.Connection("localhost", "ta", user = "******", password = "******") for name, info in infos.items(): sql = "SELECT id FROM students WHERE gs_name = %s AND pid = %s AND email = %s" if not db.get(sql, name, info['pid'], info['email']): sql = "INSERT INTO students (gs_name, pid, email, class_id) VALUES (%s, %s, %s, %s)" db.execute(sql, name, info['pid'], info['email'], mysqlClassId) cprint("%s not found, inserting" % name, 'green') else: print "%s found, doing nothing" % name