Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save anthonykrivonos/1850dab41cd40908e921027f396c7833 to your computer and use it in GitHub Desktop.
Save anthonykrivonos/1850dab41cd40908e921027f396c7833 to your computer and use it in GitHub Desktop.
# Reference: https://stackoverflow.com/a/61789978/7432026
import pymysql
db = pymysql.connect(host="ak4483-db.cfut7pwibnyz.us-east-1.rds.amazonaws.com", user="admin", passwd="adm1nadm2n", database="question_9")
cursor = db.cursor()
for i, row in people.iterrows():
person = **row
uni, firstName, lastName, email, role = person['uni'], person['first_name'], person['last_name'], person['email'], person['role']
cursor.execute('INSERT INTO people (uni, firstName, lastName, email) VALUES(%s, %s, %s, %s)', uni, firstName, lastName, email)
if role == 'S' or role == 'B':
major, graduationYear = person['major'], person['graduation_year']
cursor.execute('INSERT INTO students (major, graduationYear) VALUES(%s, %s)', major, graduationYear)
if role == 'F' or role == 'B':
major, graduationYear = person['title'], person['paygrade']
cursor.execute('INSERT INTO faculty (title, payGrade) VALUES(%s, %s)', major, graduationYear)
for i, row in courses.iterrows():
person = **row
values = [None if r == '' else r for r in row]
cursor.execute('INSERT INTO courses (courseId, title, year, semester, callNo) VALUES(%s, %s, %s, %s, %s)', values)
for i, row in people_to_courses.iterrows():
row = list(row)
values = [None if r == '' else r for r in row]
cursor.execute('INSERT INTO relationships (uni, callNo, role) VALUES(%s, %s, %s)', values)
db.commit()
cursor.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment