Skip to content

Commit 3c3c707

Browse files
Barb CutlerBarb Cutler
Barb Cutler
authored and
Barb Cutler
committed
runforever
1 parent 3f503b4 commit 3c3c707

File tree

1 file changed

+49
-7
lines changed

1 file changed

+49
-7
lines changed

PhotoScraper/RPI_SIS_PhotoScraper.py

+49-7
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
from selenium.webdriver.support.ui import WebDriverWait
1313
from selenium.webdriver.support import expected_conditions as EC
1414
from selenium.webdriver.common.keys import Keys
15-
15+
from datetime import datetime
1616

1717
##################################################################
1818
# a few optional command line argument variables
@@ -25,6 +25,10 @@
2525
help='a file containing the crns of desired courses')
2626
parser.add_argument('--headless', default=False, action="store_true",
2727
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')
2832

2933
args = parser.parse_args()
3034

@@ -238,6 +242,8 @@ def saveImagesToFolder(term, class_list):
238242
if k == "img url":
239243
img_url = class_list[i].get(k)
240244
# download and save the image to a specific folder (term/course_section) from the image url
245+
if args.no_photos:
246+
continue
241247
if img_url.split("/")[-1].strip() == "web_transparent.gif":
242248
print("Skipping {} because no photo on SIS".format(rcs_id))
243249
continue
@@ -271,7 +277,7 @@ def getStudentInfoFromCourse(driver, term):
271277

272278
try:
273279
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")
275281
try:
276282
first = driver.find_element_by_link_text('Current Record Set: 1 - 200')
277283
print ("1-200 found")
@@ -291,7 +297,7 @@ def getStudentInfoFromCourse(driver, term):
291297
print ("ERROR IN CURRENT RECORD COUNTING -- FIRST")
292298
return 0
293299
except:
294-
print ("'Current Record Set' label not found")
300+
#print ("'Current Record Set' label not found")
295301
getStudentInfoFromCourseHelper(driver,term, class_list)
296302

297303
driver.back()
@@ -490,6 +496,24 @@ def getStudentInfoFromCourseHelper(driver, term, class_list):
490496
driver.back()
491497

492498

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+
493517
##################################################################
494518
# Gets the info regarding each course of student images with their rcs id
495519
def loopOverCourses(driver,term):
@@ -562,12 +586,30 @@ def loopOverCourses(driver,term):
562586
if __name__ == "__main__":
563587
try:
564588
driver, success = login()
589+
565590
# if login is valid with correct User ID or PIN, continue the program by collecting data
566591
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 ("--------------------\nlets 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 ("----------------\nLETS RUN FOREVER\n----------------")
571613

572614
finally:
573615
# ends the program

0 commit comments

Comments
 (0)