Skip to content
This repository was archived by the owner on Jan 8, 2021. It is now read-only.

Commit 565a7a1

Browse files
committed
Add rmp scraper
1 parent 2bd86bf commit 565a7a1

File tree

1 file changed

+59
-0
lines changed

1 file changed

+59
-0
lines changed

rmp_scraper/main.py

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# Modified code based off the licence below
2+
# MIT License
3+
#
4+
# Copyright (c) 2018 Rodantny Reyes
5+
#
6+
# Permission is hereby granted, free of charge, to any person obtaining a copy
7+
# of this software and associated documentation files (the "Software"), to deal
8+
# in the Software without restriction, including without limitation the rights
9+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10+
# copies of the Software, and to permit persons to whom the Software is
11+
# furnished to do so, subject to the following conditions:
12+
#
13+
# The above copyright notice and this permission notice shall be included in all
14+
# copies or substantial portions of the Software.
15+
#
16+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22+
# SOFTWARE.
23+
24+
25+
import requests
26+
import json
27+
import math
28+
29+
def createprofessorlist():#creates List object that include basic information on all Professors from the IDed University
30+
tempprofessorlist = []
31+
num_of_prof = GetNumOfProfessors(UniversityId)
32+
num_of_pages = math.ceil(num_of_prof / 20)
33+
i = 1
34+
while (i <= num_of_pages):# the loop insert all professor into list
35+
page = requests.get("http://www.ratemyprofessors.com/filter/professor/?&page=" + str(
36+
i) + "&filter=teacherlastname_sort_s+asc&query=*%3A*&queryoption=TEACHER&queryBy=schoolId&sid=" + str(
37+
UniversityId))
38+
temp_jsonpage = json.loads(page.content)
39+
temp_list = temp_jsonpage['professors']
40+
tempprofessorlist.extend(temp_list)
41+
i += 1
42+
return tempprofessorlist
43+
44+
def GetNumOfProfessors(id): # function returns the number of professors in the university of the given ID.
45+
page = requests.get(
46+
"http://www.ratemyprofessors.com/filter/professor/?&page=1&filter=teacherlastname_sort_s+asc&query=*%3A*&queryoption=TEACHER&queryBy=schoolId&sid=" + str(
47+
id)) # get request for page
48+
temp_jsonpage = json.loads(page.content)
49+
num_of_prof = temp_jsonpage[
50+
'remaining'] + 20 # get the number of professors at William Paterson University
51+
return num_of_prof
52+
53+
54+
UniversityId = 795
55+
rpiProfessorlist = createprofessorlist()
56+
57+
print(json.dumps(rpiProfessorlist, indent=4, sort_keys=True))
58+
with open(f"rmp.json", "w") as outfile: # -{os.getenv("CURRENT_TERM")}
59+
json.dump(rpiProfessorlist , outfile, sort_keys=False, indent=2)

0 commit comments

Comments
 (0)