Wrap export in try: finally:

This commit is contained in:
Tanner Collin 2023-05-08 21:15:39 +00:00
parent c693d30394
commit 1d5f63f86d

View File

@ -12,39 +12,45 @@ chrome_options = Options()
chrome_options.add_argument('--headless')
chrome_options.add_argument('start-maximized')
chrome_options.add_argument('--no-sandbox')
driver = webdriver.Chrome(service=ser, options=chrome_options)
driver.get('https://sensors.dns.t0.vc')
time.sleep(3)
driver.execute_script("return document.getElementsByClassName('menu')[0].remove();")
try:
driver.get('https://sensors.dns.t0.vc')
time.sleep(3)
graphs = [
'Solar_Power',
'Living_Room_Air',
'Outside_Temperature',
'Bedroom_Temperature',
'Nook_Temperature',
'Misc_Temperature',
'Nook_Thermostat',
'Gas_Usage',
'Water_Usage',
'Living_Room_Lux',
]
driver.execute_script("return document.getElementsByClassName('menu')[0].remove();")
for graph in graphs:
print('Capturing', graph, 'graph...')
graphs = [
'Solar_Power',
'Living_Room_Air',
'Outside_Temperature',
'Bedroom_Temperature',
'Nook_Temperature',
'Misc_Temperature',
'Nook_Thermostat',
'Gas_Usage',
'Water_Usage',
'Living_Room_Lux',
]
try:
element = driver.find_element(By.ID, graph)
except NoSuchElementException:
print('Graph not found, skipping.')
continue
for graph in graphs:
print('Capturing', graph, 'graph...')
driver.execute_script('arguments[0].scrollIntoView({block: "center"});', element)
try:
element = driver.find_element(By.ID, graph)
except NoSuchElementException:
print('Graph not found, skipping.')
continue
with open('/home/tanner/sensors/export/data/{}.png'.format(graph), 'wb') as f:
f.write(element.screenshot_as_png)
driver.execute_script('arguments[0].scrollIntoView({block: "center"});', element)
with open('/home/tanner/sensors/export/data/{}.png'.format(graph), 'wb') as f:
f.write(element.screenshot_as_png)
finally:
driver.close()
driver.quit()
driver.close()
print('done.')