12
12
from selenium .webdriver .support .ui import WebDriverWait
13
13
from selenium .webdriver .support import expected_conditions as EC
14
14
from selenium .webdriver .common .keys import Keys
15
-
15
+ from datetime import datetime
16
16
17
17
##################################################################
18
18
# a few optional command line argument variables
25
25
help = 'a file containing the crns of desired courses' )
26
26
parser .add_argument ('--headless' , default = False , action = "store_true" ,
27
27
help = 'run program without visual display' )
28
+ parser .add_argument ('--no_photos' , default = False , action = "store_true" ,
29
+ help = 'dont save photos' )
30
+ parser .add_argument ('--run_forever' , default = False , action = "store_true" ,
31
+ help = 'keep clicking to avoid auto-timeout' )
28
32
29
33
args = parser .parse_args ()
30
34
@@ -238,6 +242,8 @@ def saveImagesToFolder(term, class_list):
238
242
if k == "img url" :
239
243
img_url = class_list [i ].get (k )
240
244
# download and save the image to a specific folder (term/course_section) from the image url
245
+ if args .no_photos :
246
+ continue
241
247
if img_url .split ("/" )[- 1 ].strip () == "web_transparent.gif" :
242
248
print ("Skipping {} because no photo on SIS" .format (rcs_id ))
243
249
continue
@@ -271,7 +277,7 @@ def getStudentInfoFromCourse(driver, term):
271
277
272
278
try :
273
279
current_record = driver .find_element_by_partial_link_text ('Current Record Set' )
274
- print ("'Current Record Set' label found" )
280
+ # print ("'Current Record Set' label found")
275
281
try :
276
282
first = driver .find_element_by_link_text ('Current Record Set: 1 - 200' )
277
283
print ("1-200 found" )
@@ -291,7 +297,7 @@ def getStudentInfoFromCourse(driver, term):
291
297
print ("ERROR IN CURRENT RECORD COUNTING -- FIRST" )
292
298
return 0
293
299
except :
294
- print ("'Current Record Set' label not found" )
300
+ # print ("'Current Record Set' label not found")
295
301
getStudentInfoFromCourseHelper (driver ,term , class_list )
296
302
297
303
driver .back ()
@@ -490,6 +496,24 @@ def getStudentInfoFromCourseHelper(driver, term, class_list):
490
496
driver .back ()
491
497
492
498
499
+ ##################################################################
500
+ # Gets the info regarding each course of student images with their rcs id
501
+ def wasteTimeClicking (driver ,seconds ):
502
+ counter = 0
503
+ while counter < seconds :
504
+ print ("wasting time" )
505
+
506
+ # click Instructors & Advisors Menu
507
+ driver .find_element_by_link_text ('Instructor & Advisor Menu' ).click ()
508
+ time .sleep (5 )
509
+
510
+ # click Select a Semester or Summer Session
511
+ driver .find_element_by_link_text ('Select a Semester or Summer Session' ).click ()
512
+ time .sleep (55 )
513
+
514
+ counter += 60
515
+
516
+
493
517
##################################################################
494
518
# Gets the info regarding each course of student images with their rcs id
495
519
def loopOverCourses (driver ,term ):
@@ -562,12 +586,30 @@ def loopOverCourses(driver,term):
562
586
if __name__ == "__main__" :
563
587
try :
564
588
driver , success = login ()
589
+
565
590
# if login is valid with correct User ID or PIN, continue the program by collecting data
566
591
if success :
567
- # Get the term to use to save images
568
- term , success = selectTerm (driver )
569
- if success :
570
- loopOverCourses (driver ,term )
592
+
593
+ while True :
594
+
595
+ # Get the term to use to save images
596
+ term , success = selectTerm (driver )
597
+
598
+ if success :
599
+ loopOverCourses (driver ,term )
600
+
601
+ sttime = datetime .now ().strftime ('%Y%m%d %H:%M:%S' )
602
+ with open ("last_completed_run.txt" , 'a' ) as logfile :
603
+ logfile .write (sttime + ' completed scrape\n ' )
604
+
605
+ if not args .run_forever :
606
+ print ("--------------------\n lets NOT run forever\n --------------------" )
607
+ break
608
+
609
+ # wait a number of hours before doing it all again
610
+ num_hours = 1
611
+ wasteTimeClicking (driver ,60 * 60 * num_hours )
612
+ print ("----------------\n LETS RUN FOREVER\n ----------------" )
571
613
572
614
finally :
573
615
# ends the program
0 commit comments