-
Notifications
You must be signed in to change notification settings - Fork 0
/
newsearch.py
58 lines (51 loc) · 2.7 KB
/
newsearch.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
import requests
import json
class University():
def __init__(self,schoolID):
self.Uni = schoolID
def searching(self, name):
parts = name.split(" ")
self.found = None
if(len(parts)==1):
one = parts[0]
namesF = self.lookLast(one)
namesL = self.lookFirst(one)
namesF.extend(namesL)
if(len(namesF)==0):
return "error"
else:
return namesF
firstN = parts[0]
lastN = parts[1]
page = requests.get("http://www.ratemyprofessors.com/filter/professor/?&page=1&filter=teacherlastname_sort_s+asc&query=" + lastN + "&queryoption=TEACHER&queryBy=schoolId&sid=" + str(self.Uni))
temp_jsonpage = json.loads(page.content)
self.temp_list = temp_jsonpage['professors']
self.found = self.lookFull(name)
if("Error" in str(self.found)):
return "Error not found!"
else:
return self.temp_list[self.found]
def lookFull(self, name):
for i in range(0, len(self.temp_list)):
print(self.temp_list[i]['tFname'] + " " + self.temp_list[i]['tLname'])
if (name == (self.temp_list[i]['tFname'] + " " + self.temp_list[i]['tLname'])):
return i
return False
def lookLast(self, name):
firstNames = []
page = requests.get("http://www.ratemyprofessors.com/filter/professor/?&page=1&filter=teacherlastname_sort_s+asc&query=" + name + "&queryoption=TEACHER&queryBy=schoolId&sid=" + str(self.Uni))
temp_jsonpage = json.loads(page.content)
self.temp_list = temp_jsonpage['professors']
for i in range(0, len(self.temp_list)):
if(name == (self.temp_list[i]['tLname'])):
firstNames.append(self.temp_list[i]['tFname'] + " " + self.temp_list[i]['tLname'] +": " + self.temp_list[i]['tDept'])
return firstNames
def lookFirst(self, name):
lastNames = []
page = requests.get("http://www.ratemyprofessors.com/filter/professor/?&page=1&filter=teacherfirstname_sort_s+asc&query=" + name + "&queryoption=TEACHER&queryBy=schoolId&sid=" + str(self.Uni))
temp_jsonpage = json.loads(page.content)
self.temp_list = temp_jsonpage['professors']
for i in range(0,len(self.temp_list)):
if(name == (self.temp_list[i]['tFname'])):
lastNames.append(self.temp_list[i]['tFname'] + " " + self.temp_list[i]['tLname'] + ": " + self.temp_list[i]['tDept'])
return lastNames