Ejemplo n.º 1
0
import requests
import json
import re
import sys
import os
import db_functions as db
from APIRequest import get_request_pcr, print_components, set_http_pcr

conn = db.get_connection()
print("Currently in db:")
db.doQuery(conn, "select count(*) from Professor;")
http_str = set_http_pcr("instructors")
json_obj = get_request_pcr(http_str)
instr_list = json_obj["result"]["values"]
for item in instr_list:
    # need to use tripple quotes because some names have ' in them
    # instructors have -1 as default avg rating
    pid = "{0}".format(item["id"])
    just_the_num = pid.split("-")[0]
    query_str = """insert into Professor (pid,name,avg_rating) VALUES("{0}","{1}",-1);""".format(
        just_the_num, item["name"])
    db.doQuery(conn, query_str)
db.close(conn)
import requests
import json
import re
import sys
import os
import db_functions as db
from APIRequest import get_request_pcr, print_components, set_http_pcr

conn = db.get_connection()

section_query = "select sid from Section;"
db.doQueryResults(conn, section_query)

cursor = conn.cursor()
cursor.execute(section_query)
row = cursor.fetchone()

while row is not None:
    info = row[0].split("-")
    code = info[0] + "-" + info[1]
    dept = info[0]
    sem = info[-1]  #last thing
    sid = row[0]

    query_str = """insert into Offered(code, did, sid, semid) values ('""" + code + """','""" + dept + """','""" + sid + """','""" + sem + """');"""
    print(query_str)
    db.doQuery(conn, query_str)
    row = cursor.fetchone()

db.close(conn)
import requests
import json
import re
import sys
import os
import db_functions as db
from APIRequest import get_request_pcr, print_components, set_http_pcr

conn = db.get_connection()
print("Currently in db:")
db.doQuery(conn, "select * from Semester;")

http_str = set_http_pcr("semesters")
json_obj = get_request_pcr(http_str)
sem_list = json_obj["result"]["values"]
for item in sem_list:
    # need to use tripple quotes because some names have ' in them
    # leave school as null because we dont know if we can get that
    query_str = """INSERT INTO Semester (semid,name) VALUES ("{0}","{1}");""".format(
        item["id"], item["name"])
    print(query_str)
    db.doQuery(conn, query_str)
db.close(conn)
Ejemplo n.º 4
0
        c_num_w_section)
    num_teaches_instances = db.doQueryResults(conn, query_str_num_teaches)
    if teaches is None:
        continue
    avg_pf_qual = 0.0
    for teach in teaches:
        #do addition
        avg_pf_qual += float(teach[2])

    #do division
    avg_diff = avg_diff / float((num_section_instances[0])[0])
    avg_qual = avg_qual / float((num_section_instances[0])[0])
    avg_num_stud = avg_num_stud / float((num_section_instances[0])[0])
    avg_wk_reqd = avg_wk_reqd / float((num_section_instances[0])[0])
    avg_rec_maj = avg_rec_maj / float((num_section_instances[0])[0])
    avg_rec_nomaj = avg_rec_nomaj / float((num_section_instances[0])[0])
    avg_com_ability = avg_com_ability / float((num_section_instances[0])[0])
    avg_pf_access = avg_pf_access / float((num_section_instances[0])[0])
    avg_num_rev = avg_num_rev / float((num_section_instances[0])[0])
    avg_stim_int = avg_stim_int / float((num_section_instances[0])[0])
    avg_pf_qual = avg_pf_qual / float((num_teaches_instances[0])[0])

    query_update_avg = "insert into SectionAverages(secid,difficulty,quality,num_students,work_required,rec_major,rec_non_major,comm_ability,prof_access,num_reviews,stim_interest,instruct_quality) values('{0}','{1}',{2},{3},'{4}','{5}','{6}','{7}','{8}','{9}','{10}','{11}');".format(
        c_num_w_section, avg_diff, avg_qual, avg_num_stud, avg_wk_reqd,
        avg_rec_maj, avg_rec_nomaj, avg_com_ability, avg_pf_access,
        avg_num_rev, avg_stim_int, avg_pf_qual)
    print query_update_avg
    db.doQuery(conn, query_update_avg)

db.close(conn)
import requests
import json
import re
import sys
import os
import db_functions as db
from APIRequest import get_request_pcr, print_components, set_http_pcr

conn = db.get_connection()
print("Currently in db:")
db.doQuery(conn, "select * from Department;")

http_str = set_http_pcr("depts")
json_obj = get_request_pcr(http_str)
dept_list = json_obj["result"]["values"]
for item in dept_list:
    # need to use tripple quotes because some names have ' in them
    # leave school as null because we dont know if we can get that
    query_str = """INSERT INTO Department (did,name,school,path) VALUES ("{0}","{1}",NULL,"{2}");""".format(
        item["id"], item["name"], item["path"])
    print(query_str)
    db.doQuery(conn, query_str)
db.close(conn)