@@ -173,24 +173,12 @@ def selectTerm(driver):
173
173
174
174
##################################################################
175
175
# 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 ):
177
177
if len (class_list ) == 0 :
178
178
return
179
179
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
-
192
180
# get path and create path if not already existed
193
- path = Path (folder_term , course_folder_name )
181
+ path = Path ("images" )
194
182
path .mkdir (exist_ok = True , parents = True )
195
183
196
184
jsonfile = []
@@ -310,9 +298,7 @@ def getStudentInfoFromCourse(driver, term):
310
298
311
299
if class_list == 0 :
312
300
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
316
302
317
303
318
304
##################################################################
@@ -572,6 +558,8 @@ def loopOverCourses(driver, term):
572
558
# click Course Information- Select a CRN
573
559
driver .find_element (By .LINK_TEXT , "Course Information- Select a CRN" ).click ()
574
560
561
+ courses = []
562
+
575
563
# if there was at least one crn in the file
576
564
if crns :
577
565
driver .find_element (
@@ -584,7 +572,7 @@ def loopOverCourses(driver, term):
584
572
crn_box .send_keys (crn )
585
573
crn_box .send_keys (Keys .TAB )
586
574
crn_box .send_keys (Keys .RETURN )
587
- getStudentInfoFromCourse (driver , term )
575
+ courses . append ( getStudentInfoFromCourse (driver , term ) )
588
576
print ("Finished processing CRN " + crn )
589
577
return
590
578
@@ -614,15 +602,15 @@ def loopOverCourses(driver, term):
614
602
elif answer == "exit" :
615
603
return
616
604
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." )
620
606
select_course .select_by_index (index )
621
607
driver .find_element (By .XPATH , "//input[@value='Submit']" ).click ()
622
- getStudentInfoFromCourse (driver , term )
608
+ courses . append ( getStudentInfoFromCourse (driver , term ) )
623
609
break
624
610
else :
625
611
print ("Invalid answer! Try again!" )
612
+ class_list = [student for course in courses for student in course ]
613
+ saveImagesToFolder (class_list )
626
614
627
615
628
616
# Assumes SIS main page is open
0 commit comments