diff --git a/waternsw_grabber/waternsw_grabber.py b/waternsw_grabber/waternsw_grabber.py index 037aa1f..6bba141 100644 --- a/waternsw_grabber/waternsw_grabber.py +++ b/waternsw_grabber/waternsw_grabber.py @@ -51,8 +51,12 @@ def wait_for_element(driver, by, x, timeout=180): Raises TimeoutException if element does not load within timeout period """ - element_present = EC.presence_of_element_located((by, x)) - WebDriverWait(driver, timeout).until(element_present) + try: + element_present = EC.presence_of_element_located((by, x)) + WebDriverWait(driver, timeout).until(element_present) + except TimeoutError: + raise TimeoutError( + 'Request timed out on {}. Try again later?'.format(bore_id)) def get_telemetered_bore(driver, bore_id, start_date, end_date): @@ -99,7 +103,7 @@ def get_telemetered_bore(driver, bore_id, start_date, end_date): wait_for_element(driver, By.XPATH, '//*[@id="tabstext"]') # Activate outputs tab, and wait for 'Get Output' button - driver.execute_script(menuloc.display_frame('gw','gwcf_org','1')) + driver.execute_script(menuloc.display_frame('gw', 'gwcf_org', '1')) driver.switch_to.parent_frame() wait_for_element(driver, By.ID, 'gwgwcf_org') driver.switch_to.frame('gwgwcf_org') @@ -214,7 +218,7 @@ def telemetered_bore_downloader(bore_ids, start_date, end_date, download_dir): pbar.set_description(bore_id) try: get_telemetered_bore(driver, bore_id, start_date, end_date) - except ValueError as e: + except (ValueError, TimeoutError) as e: logging.error(e) # Tidy up console after tqdm