# FOREIGN KEY(did) REFERENCES Department (did) ON DELETE CASCADE,
# FOREIGN KEY(code) REFERENCES Course (code) ON DELETE CASCADE
# );

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)
filler = [-1] * len(ratings_required)
ratings = dict(zip(ratings_required, filler))

http_str = set_http_pcr("depts")
json_obj = get_request_pcr(http_str)
dept_list = json_obj["result"]["values"]
for dept in dept_list:
        # leave school as null because we dont know if we can get that
        http_str = set_http_pcr(dept["path"])
        json_obj = get_request_pcr(http_str)
        course_list = json_obj["result"]["coursehistories"]
        for course in course_list:
                alias_list = course["aliases"]
                query_str = "Select code from Alias where alias='{0}';".format(alias_list[0]);
                res = db.doQueryResults(conn,query_str)
		if res is None:
			print "Error: alias not found in table" 
		else:
			code = res[0]
                	http_str = set_http_pcr(course["path"])
			json_obj = get_request_pcr(http_str)
			courses_list_2 = json_obj["result"]["courses"]
			for course_2 in courses_list_2:
				path = course_2["path"] + "/sections"
				http_str = set_http_pcr(path)
				json_obj = get_request_pcr(http_str)
				sections_list = json_obj["result"]["values"]
				for section in sections_list:
					http_str = set_http_pcr(section["reviews"]["path"])
					json_obj = get_request_pcr(http_str)
Beispiel #3
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()
last_checked = ''
query_str = 'Select sid from Section;'
courses = db.doQueryResults(conn, query_str)
for course in courses:
    split = course[0].split("-")
    c_num_w_section = split[0] + "-" + split[1] + "-" + split[2]
    if (last_checked == c_num_w_section):
        continue
    else:
        last_checked = c_num_w_section
    #find all semesters for that section
    query_str_sections = "select * from Section where sid like '{0}%';".format(
        c_num_w_section)
    sections = db.doQueryResults(conn, query_str_sections)
    #find how many there are of them
    query_str_num = "select count(*) from Section where sid like '{0}%';".format(
        c_num_w_section)
    num_section_instances = db.doQueryResults(conn, query_str_num)
    if sections is None:
        continue
    avg_diff = 0.0
    avg_qual = 0.0
    avg_num_stud = 0.0
Beispiel #4
0
# FOREIGN KEY (pid) REFERENCES Professor (pid),
# FOREIGN KEY (did) REFERENCES Department (did)
# );

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()

query = "select pid, sid from Teaches;"
db.doQueryResults(conn, query)

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

while row is not None:
    pid = row[0]
    sid = row[1]
    dept = sid.split("-")[0]

    query_str = """insert into InDepartment (pid, did) values ('""" + pid + """','""" + dept + """');"""

    print(query_str)
    db.doQuery(conn, query_str)
    row = cursor.fetchone()
Beispiel #5
0
import db_functions as db
from APIRequest import get_request_pcr, print_components, set_http_pcr
conn = db.get_connection()
from penn import Registrar

#Jack Token - locked for now
REG_USERNAME = '******'
REG_PASSWORD = '******'

#Siyin Tokem - take 2
# REG_USERNAME = '******'
# REG_PASSWORD = '******'
with open("registrar_data.csv", "w") as csv_file:
    r = Registrar(REG_USERNAME, REG_PASSWORD)
    query_str = 'Select code from Course;'
    courses = db.doQueryResults(conn, query_str)
    for course in courses:
        done = False
        split = course[0].split("-")
        dept = split[0]
        c_num = split[1]
        #s_num = '001'
        query_str = "select sid from Section where sid like '{0}%';".format(
            course[0])
        sections = db.doQueryResults(conn, query_str)
        if sections is None:
            continue
        for section in sections:
            split = section[0].split("-")
            s_num = split[2]
            sec_code = split[0] + "-" + split[1] + "-" + split[2]