diff --git a/waternsw_grabber/waternsw_grabber.py b/waternsw_grabber/waternsw_grabber.py index 7865cfc..3676bf6 100644 --- a/waternsw_grabber/waternsw_grabber.py +++ b/waternsw_grabber/waternsw_grabber.py @@ -148,9 +148,21 @@ def get_telemetered_bore(driver, bore_id, start_date, end_date): # Get date input fields fields = driver.find_elements_by_xpath('//*[starts-with(@id,"cdate")]') - # Parse dates - start_date = pd.to_datetime(start_date) - end_date = pd.to_datetime(end_date) + # Get available date ranges + datestr = driver.find_elements_by_xpath('//*/tr/td[4]/span') + dates = np.array([d.text.split(' to ') for d in datestr]) + + if start_date is not None: + start_date = pd.to_datetime(start_date) + else: + # Get date from page, if not provided + start_date = pd.to_datetime(dates[:, 0], dayfirst=True).min() + + if end_date is not None: + end_date = pd.to_datetime(end_date) + else: + # Get date from page, if not provided + end_date = pd.to_datetime(dates[:, 1], dayfirst=True).max() # Update fields with specified dates for field, date in zip(fields, [start_date, end_date]):