From cc01ba10d4bb2c25040e597f9891ca475a33ff4c Mon Sep 17 00:00:00 2001 From: Jaydin_MacBook <74679492+TheManWhoLikesToCode@users.noreply.github.com> Date: Wed, 24 Jan 2024 16:45:43 -0500 Subject: [PATCH] Added Try Catch to missing instructors --- backend/blackboard_session.py | 10 +- backend/test_blackboard_scraper.py | 162 +++++++++++++++++++++++++---- 2 files changed, 147 insertions(+), 25 deletions(-) diff --git a/backend/blackboard_session.py b/backend/blackboard_session.py index cc40f19..66588cf 100644 --- a/backend/blackboard_session.py +++ b/backend/blackboard_session.py @@ -432,10 +432,12 @@ def get_courses(self): # Process instructors and format course names for course in courses_list: try: - instructor_name = course.find("div").find( - "span", class_="name").text.strip() - last_name = instructor_name.split()[-1].rstrip(';') - if not last_name: + try: + instructor_name = course.find("div").find("span", class_="name").text.strip() + last_name = instructor_name.split()[-1].rstrip(';') + if not last_name: + last_name = "No Instructor" + except: last_name = "No Instructor" pattern = r'([A-Z]+-[0-9]+-[0-9]+[A-Z]?)|([A-Z]+-[0-9]+)' diff --git a/backend/test_blackboard_scraper.py b/backend/test_blackboard_scraper.py index 3278b1c..4599f74 100644 --- a/backend/test_blackboard_scraper.py +++ b/backend/test_blackboard_scraper.py @@ -151,17 +151,77 @@ def test_enable_instructors_logged_in(self): with patch.object(session, '_get_request') as mock_get_request: mock_get_request.return_value.status_code = 200 mock_get_request.return_value.content = ''' - + + +
+ +