Skip to content

Commit 3252a65

Browse files
committed
[Refactor:Photoscraper] Refactor to dump images into 1 dir
1 parent 11a00fd commit 3252a65

File tree

1 file changed

+10
-22
lines changed

1 file changed

+10
-22
lines changed

PhotoScraper/RPI_SIS_PhotoScraper.py

Lines changed: 10 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -173,24 +173,12 @@ def selectTerm(driver):
173173

174174
##################################################################
175175
# Saves the images with rcs id as image name to a term/course folder
176-
def saveImagesToFolder(term, class_list):
176+
def saveImagesToFolder(class_list):
177177
if len(class_list) == 0:
178178
return
179179

180-
course_crn = class_list[0]["course_crn"]
181-
course_prefix = class_list[0]["course_prefix"]
182-
course_name = class_list[0]["course_name"]
183-
course_section = class_list[0]["course_section"]
184-
course_number = class_list[0]["course_number"]
185-
186-
course_folder_name = "{}-{}-{}".format(course_prefix, course_number, course_section)
187-
188-
# make term (month year) into month-year
189-
term_elements = term.split()
190-
folder_term = term_elements[0] + "-" + term_elements[1]
191-
192180
# get path and create path if not already existed
193-
path = Path(folder_term, course_folder_name)
181+
path = Path("images")
194182
path.mkdir(exist_ok=True, parents=True)
195183

196184
jsonfile = []
@@ -310,9 +298,7 @@ def getStudentInfoFromCourse(driver, term):
310298

311299
if class_list == 0:
312300
print("Warning: this class size is 0")
313-
else:
314-
# Use the info collected and save the image with rcs id for term/course in current directory
315-
saveImagesToFolder(term, class_list)
301+
return class_list
316302

317303

318304
##################################################################
@@ -572,6 +558,8 @@ def loopOverCourses(driver, term):
572558
# click Course Information- Select a CRN
573559
driver.find_element(By.LINK_TEXT, "Course Information- Select a CRN").click()
574560

561+
courses = []
562+
575563
# if there was at least one crn in the file
576564
if crns:
577565
driver.find_element(
@@ -584,7 +572,7 @@ def loopOverCourses(driver, term):
584572
crn_box.send_keys(crn)
585573
crn_box.send_keys(Keys.TAB)
586574
crn_box.send_keys(Keys.RETURN)
587-
getStudentInfoFromCourse(driver, term)
575+
courses.append(getStudentInfoFromCourse(driver, term))
588576
print("Finished processing CRN " + crn)
589577
return
590578

@@ -614,15 +602,15 @@ def loopOverCourses(driver, term):
614602
elif answer == "exit":
615603
return
616604
elif answer == "y":
617-
print(
618-
"Getting student pictures... (this could take a few seconds per student)"
619-
)
605+
print("Getting list of students. Will scrape them upon exiting.")
620606
select_course.select_by_index(index)
621607
driver.find_element(By.XPATH, "//input[@value='Submit']").click()
622-
getStudentInfoFromCourse(driver, term)
608+
courses.append(getStudentInfoFromCourse(driver, term))
623609
break
624610
else:
625611
print("Invalid answer! Try again!")
612+
class_list = [student for course in courses for student in course]
613+
saveImagesToFolder(class_list)
626614

627615

628616
# Assumes SIS main page is open

0 commit comments

Comments
 (0)