From fb0fd5e8b72f8e2aa628f9651ed59d2a117c2c14 Mon Sep 17 00:00:00 2001 From: Daniel Howe Date: Wed, 13 Mar 2019 07:09:54 +1100 Subject: [PATCH] Get start and end dates automatically if not provided --- waternsw_grabber/waternsw_grabber.py | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) 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]):