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,13 +12,16 @@ 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 = [
driver.execute_script("return document.getElementsByClassName('menu')[0].remove();")
graphs = [
'Solar_Power',
'Living_Room_Air',
'Outside_Temperature',
@ -29,9 +32,9 @@ graphs = [
'Gas_Usage',
'Water_Usage',
'Living_Room_Lux',
]
]
for graph in graphs:
for graph in graphs:
print('Capturing', graph, 'graph...')
try:
@ -45,6 +48,9 @@ for graph in graphs:
with open('/home/tanner/sensors/export/data/{}.png'.format(graph), 'wb') as f:
f.write(element.screenshot_as_png)
driver.close()
finally:
driver.close()
driver.quit()
print('done.')