Esempio n. 1
0
def update_new_column(column_name):
    add_new_column(column_name)
    connection = sdatabase.get_connection(DB_PATH, DB_NAME)

    with connection.cursor() as cursor:
        Buffer = 0 
        count = 0
        for course_dict in parse_json(get_all_courses_json()):
            if "Summer" not in course_dict['term']:
                print(course_dict['cID'], course_dict['lecNum'])
                cID = course_dict['cID']
                lecNum = course_dict['lecNum']
                enrolment = course_dict['currentEnrollment']
                term = __transform_term(course_dict['term'])
                try:
                    for i in range(len(course_dict['lecNum'])):
                        sdatabase.new_update_spot_new_column(cursor, column_name, cID, lecNum[i], enrolment[i], term)
                except:
                    print("error when inserting {}".format(course_dict))
                    continue
                count += 1
                Buffer += 1
                if Buffer == COMMIT_BUFFER:
                    print("{}th time insert course data successfully".format(count))
                    sdatabase.commit_data(connection)
                    Buffer = 0

    sdatabase.commit_data(connection)
    connection.close()
Esempio n. 2
0
def update_new_column(column_name):
    add_new_column(column_name)

    connection = sdatabase.get_connection(DB_PATH, DB_NAME)

    commit_count = 0
    with connection.cursor() as cursor:
        for semester in SEMESTERS:
            for item in process_json(get_json_of_course_list(semester)):
                cID = item['cID']
                lecNum = item['session']
                print(cID, lecNum)
                enrolment = item['actualEnrolment']
                waitlist = item['actualWaitlist']

                sdatabase.update_spot_new_column(cursor, column_name, cID,
                                                 lecNum, enrolment)
                sdatabase.update_wl_new_column(cursor, column_name, cID,
                                               lecNum, waitlist)

                commit_count += 1
                if commit_count >= COMMIT_BUFFER:
                    commit_count = 0
                    sdatabase.commit_data(connection)
    sdatabase.commit_data(connection)
    connection.close()
Esempio n. 3
0
def init_db(path, DB_NAME):
    sdatabase.init_db(path, DB_NAME)
    connection = sdatabase.get_connection(DB_PATH, DB_NAME)

    commit_count = 0

    with connection.cursor() as cursor:
        for semester in SEMESTERS:
            for item in process_json(get_json_of_course_list(semester)):
                cID = item['cID']
                lecNum = item['session']
                print(cID, lecNum)
                capacity = item['enrollmentCapacity']
                sdatabase.init_spot(cursor, cID, lecNum, capacity)
                sdatabase.init_wl(cursor, cID, lecNum)

                commit_count += 1
                if commit_count >= COMMIT_BUFFER:
                    commit_count = 0
                    sdatabase.commit_data(connection)
    sdatabase.commit_data(connection)
    connection.close()
Esempio n. 4
0
def add_new_column(column_name):
    connection = sdatabase.get_connection(DB_PATH, DB_NAME)
    with connection.cursor() as cursor:
        sdatabase.add_new_column(cursor, column_name)