Get start and end dates automatically if not provided

master
Daniel Howe 6 years ago
parent 6d2e0f89c5
commit fb0fd5e8b7

@ -148,9 +148,21 @@ def get_telemetered_bore(driver, bore_id, start_date, end_date):
# Get date input fields # Get date input fields
fields = driver.find_elements_by_xpath('//*[starts-with(@id,"cdate")]') fields = driver.find_elements_by_xpath('//*[starts-with(@id,"cdate")]')
# Parse dates # 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) 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) 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 # Update fields with specified dates
for field, date in zip(fields, [start_date, end_date]): for field, date in zip(fields, [start_date, end_date]):

Loading…
Cancel
Save