def mentor_info(username): # connecting to our database mydb = mysql.connector.connect(host="ix.cs.uoregon.edu", user="******", passwd="guest", database="mentor", port="3141") # using a cursor to add into the databse mycursor = mydb.cursor() # fetching all query = "SELECT * FROM mentor" mycursor.execute(query) myresult = mycursor.fetchall() for row in myresult: if (row[7] == username): age = int(row[2]) qs = row[4].split(",") for i in range(len(qs)): qs[i] = int(qs[i]) result = c.User(1, row[0], row[1], age, row[3], qs, row[5], row[6], row[7], row[8]) try: return result except: return c.User(-1, None, None, 0, None, {}, None, None, None, None)
def extract_mentees(): # connecting to our database mydb = mysql.connector.connect(host="ix.cs.uoregon.edu", user="******", passwd="guest", database="mentor", port="3141") # using a cursor to add into the databse mycursor = mydb.cursor() # fetching all query = "SELECT * FROM mentee" mycursor.execute(query) myresult = mycursor.fetchall() result = [] for row in myresult: age = int(row[2]) qs = row[4].split(",") for i in range(len(qs)): qs[i] = int(qs[i]) result.append(c.User(0, row[0], row[1], age, row[3], qs, row[5], row[6], row[7], row[8])) return result
def create_account(User): # Checks if mentor of mentee if User.user_type: create_mentor(User) else: create_mentee(User) # Initializes current user c.current_user = c.User(0, "", "", 0, "", [], "", "", "", "") # Adds users to users[] if havent already. if len(c.users) <= 1: c.users.extend(extract_mentees()) c.users.extend(extract_mentors()) # initialize current user to this user c.current_user = User c.users.append(c.current_user) # Gets current users matches. c.pref_check(c.current_user) c.compat(c.current_user) return c.current_user