Beispiel #1
0
def get_catalogs(subject, term=default_term):
    term_code = convert_term_to_code(term)
    param ='term_in={0}&call_proc_in=bwckctlg.p_disp_dyn_ctlg&sel_subj=dummy&sel_levl=dummy&sel_schd=dummy&sel_coll=dummy&sel_divs=dummy&sel_dept=dummy&sel_attr=dummy&sel_subj={1}&sel_crse_strt=&sel_crse_end=&sel_title=&sel_levl=%25&sel_schd=%25&sel_coll=%25&sel_divs=%25&sel_dept=%25&sel_from_cred=&sel_to_cred=&sel_attr=%25'
    param = param.format(term_code, subject)
    resp = get_conn(catalog_display_url, catalog_search_url, param, True);
    if resp.status !=200:
        return None
    else:
        content = resp.read()
        tree = etree.HTML(content)
        table = tree.xpath('./body/div/table[@class="datadisplaytable"]')[0]
        catalogs = []
        rows = table.findall('tr');
        for index in range(0, len(rows), 2):
            title_row = rows[index]
            element_a_set = title_row.findall('td/a')
            title = element_a_set[0].text
            # handle title
            split_index = title.find(' - ')
            course = title[:split_index].replace(' ','')
            name = title[split_index+3:]

            detail_row = rows[index+1]
            _iter = detail_row.itertext()
            _iter.next()
            description = _iter.next()
            description = description.strip('\n')

            catalog = {
                'course': course,
                'name': name,
                'description': description,
            }
            catalogs.append(catalog)
        return catalogs
Beispiel #2
0
def get_catalogs(subject, term=default_term):
    term_code = convert_term_to_code(term)
    param = 'term_in={0}&call_proc_in=bwckctlg.p_disp_dyn_ctlg&sel_subj=dummy&sel_levl=dummy&sel_schd=dummy&sel_coll=dummy&sel_divs=dummy&sel_dept=dummy&sel_attr=dummy&sel_subj={1}&sel_crse_strt=&sel_crse_end=&sel_title=&sel_levl=%25&sel_schd=%25&sel_coll=%25&sel_divs=%25&sel_dept=%25&sel_from_cred=&sel_to_cred=&sel_attr=%25'
    param = param.format(term_code, subject)
    resp = get_conn(catalog_display_url, catalog_search_url, param, True)
    if resp.status != 200:
        return None
    else:
        content = resp.read()
        tree = etree.HTML(content)
        table = tree.xpath('./body/div/table[@class="datadisplaytable"]')[0]
        catalogs = []
        rows = table.findall('tr')
        for index in range(0, len(rows), 2):
            title_row = rows[index]
            element_a_set = title_row.findall('td/a')
            title = element_a_set[0].text
            # handle title
            split_index = title.find(' - ')
            course = title[:split_index].replace(' ', '')
            name = title[split_index + 3:]

            detail_row = rows[index + 1]
            _iter = detail_row.itertext()
            _iter.next()
            description = _iter.next()
            description = description.strip('\n')

            catalog = {
                'course': course,
                'name': name,
                'description': description,
            }
            catalogs.append(catalog)
        return catalogs
Beispiel #3
0
def get_all_subjects(term=default_term):
	subjects = get_subjects(term)
	all_courses = []
	for subject in subjects:
		all_courses.append([subject[0], subject[1], get_sections(subject[0],term)])
		print 'Finished %s' % subject[0]
	term_code = convert_term_to_code(term)
	f = open('%s.json'%term_code, 'w')
	import json
	j = json.dumps(all_courses)
	f.write(j)
	f.flush()
	f.close()
Beispiel #4
0
def get_all_subjects(term=default_term):
    subjects = get_subjects(term)
    all_courses = []
    for subject in subjects:
        all_courses.append([subject[0], subject[1], get_sections(subject[0], term)])
        print "Finished %s" % subject[0]
    term_code = convert_term_to_code(term)
    f = open("%s.json" % term_code, "w")
    import json

    j = json.dumps(all_courses)
    f.write(j)
    f.flush()
    f.close()
Beispiel #5
0
def get_seats_by_term(request):
    term = request.GET.get('term')
    crn = request.GET.get('crn')
    if not term or not crn:
        return HttpResponse('')
    term_code = convert_term_to_code(term)
    max_num, taken_num = get_seats(crn, term_code)
    remain_num = max_num - taken_num
    seats = {
        'max': max_num,
        'remain': remain_num,
        'taken': taken_num,
    }
    seats_j = json.dumps(seats)
    return HttpResponse(seats_j, content_type="application/json")
Beispiel #6
0
def get_seats_by_term(request):
    term = request.GET.get('term')
    crn = request.GET.get('crn')
    if not term or not crn:
        return HttpResponse('')
    term_code = convert_term_to_code(term)
    max_num, taken_num = get_seats(crn, term_code)
    remain_num = max_num - taken_num
    seats = {
        'max':max_num,
        'remain':remain_num,
        'taken':taken_num,
    }
    seats_j = json.dumps(seats)
    return HttpResponse(seats_j, content_type="application/json")
Beispiel #7
0
def get_all_catalogs(term=default_term):
    subjects = get_subjects(term)
    all_catalogs = {}
    for subject in subjects:
        catalogs = get_catalogs(subject[0], term)
        for catalog in catalogs:
            all_catalogs[catalog['course']]=catalog
        print 'Finished %s' % subject[0]
    term_code = convert_term_to_code(term)
    f = open('%s_catalogs.json'%term_code, 'w')
    import json
    j = json.dumps(all_catalogs)
    f.write(j)
    f.flush()
    f.close()
Beispiel #8
0
def get_all_catalogs(term=default_term):
    subjects = get_subjects(term)
    all_catalogs = {}
    for subject in subjects:
        catalogs = get_catalogs(subject[0], term)
        for catalog in catalogs:
            all_catalogs[catalog['course']] = catalog
        print 'Finished %s' % subject[0]
    term_code = convert_term_to_code(term)
    f = open('%s_catalogs.json' % term_code, 'w')
    import json
    j = json.dumps(all_catalogs)
    f.write(j)
    f.flush()
    f.close()
Beispiel #9
0
def get_subjects(term=default_term):
	subjects = []
	p_calling_proc = 'bwckschd.p_disp_dyn_sched'
	p_term = convert_term_to_code(term)
	param = {'p_calling_proc' : p_calling_proc, 'p_term' : p_term}
	resp = get_conn(subject_url, select_term_url, param);
	if resp.status != 200:
		return None
	else:
		content = resp.read()
		tree = etree.HTML(content)
		subject_set = tree.xpath('.//select[@name="sel_subj"]')[0].findall('option')
		for option in subject_set:
			sub_code = option.attrib['value']
			sub_name = option.text[len(sub_code):].strip('\n\r- ')
			subjects.append([sub_code,sub_name])
		return subjects
Beispiel #10
0
def get_subjects(term=default_term):
    subjects = []
    p_calling_proc = "bwckschd.p_disp_dyn_sched"
    p_term = convert_term_to_code(term)
    param = {"p_calling_proc": p_calling_proc, "p_term": p_term}
    resp = get_conn(subject_url, select_term_url, param)
    if resp.status != 200:
        return None
    else:
        content = resp.read()
        tree = etree.HTML(content)
        subject_set = tree.xpath('.//select[@name="sel_subj"]')[0].findall("option")
        for option in subject_set:
            sub_code = option.attrib["value"]
            sub_name = option.text[len(sub_code) :].strip("\n\r- ")
            subjects.append([sub_code, sub_name])
        return subjects
Beispiel #11
0
def get_sections(subject, term=default_term):
	term_code = convert_term_to_code(term)
	param = 'term_in={0}&sel_subj=dummy&sel_day=dummy&sel_schd=dummy&sel_insm=dummy&sel_camp=dummy&sel_levl=dummy&sel_sess=dummy&sel_instr=dummy&sel_ptrm=dummy&sel_attr=dummy&sel_subj={1}&sel_crse=&sel_title=&sel_schd=%25&sel_from_cred=&sel_to_cred=&sel_camp=%25&sel_ptrm=%25&sel_instr=%25&sel_sess=%25&sel_attr=%25&begin_hh=0&begin_mi=0&begin_ap=a&end_hh=0&end_mi=0&end_ap=a'
	param = param.format(term_code, subject)
	resp = get_conn(section_url, subject_url, param, True);
	if resp.status !=200:
		return None
	else:
		content = resp.read()
		tree = etree.HTML(content)
		#return tree
		table = tree.xpath('./body/div/table[@class="datadisplaytable"]')[0]
		courses = {}
		rows = table.findall('tr');
		for index in range(0, len(rows), 2):
			section = {}
			title_row = rows[index]
			element_a_set = title_row.findall('th/a')
			title = element_a_set[0].text

			crn = re.findall(' - \d{5} - ',title)[0]
			section['crn']=crn.strip(' -');
			section_name = title[:title.find(crn)]
			section['name']=section_name
			title = title[title.find(crn)+len(crn):]
			_strs = title.split(' - ')
			#section['subject']=_strs[0].split(' ')[0]
			cnbr = _strs[0].split(' ')[1]
			section['number']=_strs[1]

			if len(element_a_set) > 1:
				_iter = title_row.itertext()
				_iter.next()
				_iter.next()
				link_id = _iter.next()
				link_id = link_id.strip(u'\xa0').split(': ')[1]
				section['linked_id'] = link_id
				_iter.next()
				required_link_id = _iter.next()
				required_link_id = required_link_id.strip('()');
				section['required_link_id'] = required_link_id;

			detail_row = rows[index+1]
			schedule_tables = detail_row.find('td/table').findall('tr')[1:]
			meetings = []
			for schedule_table in schedule_tables:
				meeting = {}
				_iter = schedule_table.itertext()
				for i in range(3):
					_iter.next()
				meeting['time'] = _iter.next()
				_iter.next()
				meeting['days'] = _iter.next().replace(u'\xa0','None')
				_iter.next()
				meeting['location'] = _iter.next()
				_iter.next()
				meeting['date'] = _iter.next()
				_iter.next()
				meeting['type'] = _iter.next()
				_iter.next()
				instructor = _iter.next().strip(' (')
				meeting['instructor'] = re.sub(' +',' ', instructor)
				meetings.append(meeting)
			section['meetings'] = meetings

			if courses.has_key(cnbr):
				courses[cnbr]['sections'].append(section)
				#if not section_name == courses[cnbr]['name']:
				#	raise Exception('Different name for same course %s %s' %(subject, cnbr))
			else:
				courses[cnbr] = {}
				courses[cnbr]['sections'] = [section,]
				courses[cnbr]['name'] = section_name
		return courses
Beispiel #12
0
def get_all_by_term(request, term):
    term_code = convert_term_to_code(term)
    f = open('%s/pu_class/%s.json' % (PROJECT_DIR, term_code), 'r')
    courses_j = f.read()
    return HttpResponse(courses_j, content_type="application/json")
Beispiel #13
0
def get_all_by_term(request, term):
    term_code = convert_term_to_code(term)
    f = open('%s/pu_class/%s.json'%(PROJECT_DIR,term_code), 'r')
    courses_j = f.read()
    return HttpResponse(courses_j, content_type="application/json")
Beispiel #14
0
def get_sections(subject, term=default_term):
    term_code = convert_term_to_code(term)
    param = "term_in={0}&sel_subj=dummy&sel_day=dummy&sel_schd=dummy&sel_insm=dummy&sel_camp=dummy&sel_levl=dummy&sel_sess=dummy&sel_instr=dummy&sel_ptrm=dummy&sel_attr=dummy&sel_subj={1}&sel_crse=&sel_title=&sel_schd=%25&sel_from_cred=&sel_to_cred=&sel_camp=%25&sel_ptrm=%25&sel_instr=%25&sel_sess=%25&sel_attr=%25&begin_hh=0&begin_mi=0&begin_ap=a&end_hh=0&end_mi=0&end_ap=a"
    param = param.format(term_code, subject)
    resp = get_conn(section_url, subject_url, param, True)
    if resp.status != 200:
        return None
    else:
        content = resp.read()
        tree = etree.HTML(content)
        # return tree
        table = tree.xpath('./body/div/table[@class="datadisplaytable"]')[0]
        courses = {}
        rows = table.findall("tr")
        for index in range(0, len(rows), 2):
            section = {}
            title_row = rows[index]
            element_a_set = title_row.findall("th/a")
            title = element_a_set[0].text

            crn = re.findall(" - \d{5} - ", title)[0]
            section["crn"] = crn.strip(" -")
            section_name = title[: title.find(crn)]
            section["name"] = section_name
            title = title[title.find(crn) + len(crn) :]
            _strs = title.split(" - ")
            # section['subject']=_strs[0].split(' ')[0]
            cnbr = _strs[0].split(" ")[1]
            section["number"] = _strs[1]

            if len(element_a_set) > 1:
                _iter = title_row.itertext()
                _iter.next()
                _iter.next()
                link_id = _iter.next()
                link_id = link_id.strip(u"\xa0").split(": ")[1]
                section["linked_id"] = link_id
                _iter.next()
                required_link_id = _iter.next()
                required_link_id = required_link_id.strip("()")
                section["required_link_id"] = required_link_id

            detail_row = rows[index + 1]
            schedule_tables = detail_row.find("td/table").findall("tr")[1:]
            meetings = []
            for schedule_table in schedule_tables:
                meeting = {}
                _iter = schedule_table.itertext()
                for i in range(3):
                    _iter.next()
                meeting["time"] = _iter.next()
                _iter.next()
                meeting["days"] = _iter.next().replace(u"\xa0", "None")
                _iter.next()
                meeting["location"] = _iter.next()
                _iter.next()
                meeting["date"] = _iter.next()
                _iter.next()
                meeting["type"] = _iter.next()
                _iter.next()
                instructor = _iter.next().strip(" (")
                meeting["instructor"] = re.sub(" +", " ", instructor)
                meetings.append(meeting)
            section["meetings"] = meetings

            if courses.has_key(cnbr):
                courses[cnbr]["sections"].append(section)
                # if not section_name == courses[cnbr]['name']:
                # 	raise Exception('Different name for same course %s %s' %(subject, cnbr))
            else:
                courses[cnbr] = {}
                courses[cnbr]["sections"] = [section]
                courses[cnbr]["name"] = section_name
        return courses