Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor:InstructorUI] Refactor to dump images into 1 dir #32

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 10 additions & 25 deletions PhotoScraper/RPI_SIS_PhotoScraper.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,24 +173,12 @@ def selectTerm(driver):

##################################################################
# Saves the images with rcs id as image name to a term/course folder
def saveImagesToFolder(term, class_list):
def saveImagesToFolder(class_list):
if len(class_list) == 0:
return

course_crn = class_list[0]["course_crn"]
course_prefix = class_list[0]["course_prefix"]
course_name = class_list[0]["course_name"]
course_section = class_list[0]["course_section"]
course_number = class_list[0]["course_number"]

course_folder_name = "{}-{}-{}".format(course_prefix, course_number, course_section)

# make term (month year) into month-year
term_elements = term.split()
folder_term = term_elements[0] + "-" + term_elements[1]

# get path and create path if not already existed
path = Path(folder_term, course_folder_name)
path = Path("images")
path.mkdir(exist_ok=True, parents=True)

jsonfile = []
Expand Down Expand Up @@ -310,9 +298,7 @@ def getStudentInfoFromCourse(driver, term):

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


##################################################################
Expand Down Expand Up @@ -446,9 +432,6 @@ def getStudentInfoFromCourseHelper(driver, term, class_list):
input()
raise

img_url = driver.current_url
driver.get(img_url)

# image, initalize to empty string
student_record["img url"] = ""
image_arr = driver.find_elements(By.TAG_NAME, "img")
Expand Down Expand Up @@ -575,6 +558,8 @@ def loopOverCourses(driver, term):
# click Course Information- Select a CRN
driver.find_element(By.LINK_TEXT, "Course Information- Select a CRN").click()

courses = []

# if there was at least one crn in the file
if crns:
driver.find_element(
Expand All @@ -587,7 +572,7 @@ def loopOverCourses(driver, term):
crn_box.send_keys(crn)
crn_box.send_keys(Keys.TAB)
crn_box.send_keys(Keys.RETURN)
getStudentInfoFromCourse(driver, term)
courses.append(getStudentInfoFromCourse(driver, term))
print("Finished processing CRN " + crn)
return

Expand Down Expand Up @@ -617,15 +602,15 @@ def loopOverCourses(driver, term):
elif answer == "exit":
return
elif answer == "y":
print(
"Getting student pictures... (this could take a few seconds per student)"
)
print("Getting list of students. Will scrape them upon exiting.")
select_course.select_by_index(index)
driver.find_element(By.XPATH, "//input[@value='Submit']").click()
getStudentInfoFromCourse(driver, term)
courses.append(getStudentInfoFromCourse(driver, term))
break
else:
print("Invalid answer! Try again!")
class_list = set([student for course in courses for student in course])
saveImagesToFolder(list(class_list))


# Assumes SIS main page is open
Expand Down
Loading