-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGet_Sorted_CRNs.py
69 lines (59 loc) · 1.77 KB
/
Get_Sorted_CRNs.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
import requests
from bs4 import BeautifulSoup
from class_search_web_scrapping import GetOptions, GetClasses
import time
# Returns a list that is redonk large. Use Write_Courses_iter to return a generator with smaller pieces
def Write_Courses():
Options = GetOptions()
subjects = Options[3].values()
term = "201520"
ATTR = '0ANY'
Division = "UG"
Campus = "M"
Credit = "A"
Courses = GetClasses(term, subjects, Credit, ATTR, Division, Campus)
return Courses
def Write_Courses_iter():
Options = GetOptions()
subjects = Options[3].values()
term = "201520"
ATTR = '0ANY'
Division = "UG"
Campus = "M"
Credit = "A"
for subject in subjects:
Courses = GetClasses(term, subject, Credit, ATTR, Division, Campus)
yield Courses
def Get_CRN_List():
crn_list = []
with open('/home/flask/class_text/sorted_CRNs.txt', "r") as f:
crn_list = f.read().split("\n")
while crn_list[-1] == "":
crn_list.pop()
return [i for i in crn_list]
# def Get_Crns():
# Courses = Write_Courses_iter()
# CRNs = {}
# Sorted_Crns = []
# for course in Courses:
# CRNs[course["CRN"]] = course["Title"] + "|" + course["Course - Sec"] + "|" + course["CRN"] + "|" + course["Opn"]
# Sorted_Crns = sorted(CRNs.keys())
# return Sorted_Crns, CRNs
# Performs a binary search for value in CRN_Numbers
# returns a department if the crn value was found that cooresponds to the crn
# returns false if value not in CRN_Numbers
def is_Valid(value, CRN_Numbers):
start = 0
end = len(CRN_Numbers) - 1
middle = (end) / 2
while start <= end:
middle_value = int(CRN_Numbers[middle].split(" ")[0])
if middle_value > value:
end = middle - 1
middle = (start + end) / 2
elif middle_value < value:
start = middle + 1
middle = (start + end) / 2
else:
return CRN_Numbers[middle].split(" ")[1]
return False