Wrap export in try: finally:
This commit is contained in:
parent
c693d30394
commit
1d5f63f86d
|
@ -12,39 +12,45 @@ chrome_options = Options()
|
||||||
chrome_options.add_argument('--headless')
|
chrome_options.add_argument('--headless')
|
||||||
chrome_options.add_argument('start-maximized')
|
chrome_options.add_argument('start-maximized')
|
||||||
chrome_options.add_argument('--no-sandbox')
|
chrome_options.add_argument('--no-sandbox')
|
||||||
|
|
||||||
driver = webdriver.Chrome(service=ser, options=chrome_options)
|
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();")
|
||||||
'Solar_Power',
|
|
||||||
'Living_Room_Air',
|
|
||||||
'Outside_Temperature',
|
|
||||||
'Bedroom_Temperature',
|
|
||||||
'Nook_Temperature',
|
|
||||||
'Misc_Temperature',
|
|
||||||
'Nook_Thermostat',
|
|
||||||
'Gas_Usage',
|
|
||||||
'Water_Usage',
|
|
||||||
'Living_Room_Lux',
|
|
||||||
]
|
|
||||||
|
|
||||||
for graph in graphs:
|
graphs = [
|
||||||
print('Capturing', graph, 'graph...')
|
'Solar_Power',
|
||||||
|
'Living_Room_Air',
|
||||||
|
'Outside_Temperature',
|
||||||
|
'Bedroom_Temperature',
|
||||||
|
'Nook_Temperature',
|
||||||
|
'Misc_Temperature',
|
||||||
|
'Nook_Thermostat',
|
||||||
|
'Gas_Usage',
|
||||||
|
'Water_Usage',
|
||||||
|
'Living_Room_Lux',
|
||||||
|
]
|
||||||
|
|
||||||
try:
|
for graph in graphs:
|
||||||
element = driver.find_element(By.ID, graph)
|
print('Capturing', graph, 'graph...')
|
||||||
except NoSuchElementException:
|
|
||||||
print('Graph not found, skipping.')
|
|
||||||
continue
|
|
||||||
|
|
||||||
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:
|
driver.execute_script('arguments[0].scrollIntoView({block: "center"});', element)
|
||||||
f.write(element.screenshot_as_png)
|
|
||||||
|
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.')
|
print('done.')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user