From 53345e37876030efde9ea58c4292145216b2a088 Mon Sep 17 00:00:00 2001 From: Dan Howe Date: Thu, 21 Feb 2019 16:18:51 +1100 Subject: [PATCH] Handle errors for sites with no data --- waternsw_grabber/waternsw_grabber.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/waternsw_grabber/waternsw_grabber.py b/waternsw_grabber/waternsw_grabber.py index 96577be..10ce8dc 100644 --- a/waternsw_grabber/waternsw_grabber.py +++ b/waternsw_grabber/waternsw_grabber.py @@ -89,8 +89,10 @@ def get_telemetered_bore(driver, bore_id, start_date, end_date): time.sleep(0.5) # Detect if bore record does not exist - if body_text.startswith('No SITE record found for site'): + if 'No SITE record found for site' in body_text: raise ValueError('No SITE record found for site {}'.format(bore_id)) + elif 'No variables data found for this site.' in body_text: + raise ValueError('No variables data found for site {}'.format(bore_id)) # Wait for navigation tabs wait_for_element(driver, By.XPATH, '//*[@id="tabstext"]') @@ -212,8 +214,8 @@ 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: - logging.error('Failed to download {}\n'.format(bore_id)) + except ValueError as e: + logging.error(e) # Tidy up console after tqdm print('\n')