This commit is contained in:
Jan-Henrik 2023-02-07 21:54:15 +01:00
parent c2070e05c6
commit 7e20d88f1a
2 changed files with 6 additions and 5 deletions

View file

@ -1,6 +1,6 @@
---
name: Screenshotter
version: 1.0.1.6
version: 1.0.1.7
#image: ghcr.io/maxwinterstein/homeassistant-addon-toogoodtogo-ha-mqtt-bridge-{arch}
slug: screenshotter
description: Screenshot images for E-Paper pricetags

View file

@ -40,8 +40,7 @@ for image in config["images"]:
while True:
for i, task in enumerate(tasks):
now = datetime.datetime.now()
if task["next_execution"] > now:
if task["next_execution"] > datetime.datetime.now():
continue
print(f"Running {task['name']}")
driver = webdriver.Chrome(options=chrome_options, desired_capabilities=d)
@ -51,9 +50,11 @@ while True:
if task.get("ha_auth"):
print("Doing HA Auth")
driver.execute_script(f"window.localStorage.setItem('hassTokens', {{hassUrl: '{ha_url}', access_token: '{ha_token}', token_type: 'Bearer'}});")
print(driver.execute_script(f"window.localStorage.setItem('hassTokens', {{hassUrl: '{ha_url}', access_token: '{ha_token}', token_type: 'Bearer'}});"))
print(driver.execute_script(f"return window.localStorage.getItem('hassTokens');"))
driver.get(task["url"])
time.sleep(int(wait))
print(driver.execute_script(f"return window.localStorage.getItem('hassTokens');"))
print("Making screenshot")
@ -67,6 +68,6 @@ while True:
image = image.rotate(int(rotate), expand=True)
file_name = f'{image_path}/{task["name"]}.png'
image.save(file_name)
tasks[i]["next_execution"] = now + datetime.timedelta(minutes=task["period_minutes"])
tasks[i]["next_execution"] = datetime.datetime.now() + datetime.timedelta(minutes=task["period_minutes"])
print(f"Task finished, next execution: {tasks[i]['next_execution']}")
time.sleep(1)