Use croniter

This commit is contained in:
Jan-Henrik 2023-02-08 22:52:52 +01:00
parent 04933768a6
commit 21511c669c
4 changed files with 9 additions and 4 deletions

View file

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

View file

@ -5,6 +5,7 @@ import time, os
from selenium.webdriver.common.desired_capabilities import DesiredCapabilities
import yaml
import datetime
import croniter
# enable browser logging
d = DesiredCapabilities.CHROME
@ -35,7 +36,10 @@ with open(config_file, "r") as stream:
tasks = []
for image in config["images"]:
image["next_execution"] = datetime.datetime.now()
now = datetime.datetime.now()
image["croniter"] = croniter.croniter(image["cron"], now)
image["next_execution"] = image["croniter"].get_next(datetime.datetime)
print(f"First execution of {image['name']} at {image['next_execution']}.")
tasks += [image]
while True:
@ -66,6 +70,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"] = datetime.datetime.now() + datetime.timedelta(minutes=task["period_minutes"])
tasks[i]["next_execution"] = task["croniter"].get_next(datetime.datetime)
print(f"Task finished, next execution: {tasks[i]['next_execution']}")
time.sleep(1)

View file

@ -1,4 +1,4 @@
images:
- name: "001100"
url: https://ha.baubs.net/lovelace-teflons/0?kiosk
period_minutes: 1
cron: "*/5 * * * *"

View file

@ -1,3 +1,4 @@
selenium
Pillow
pyyaml
croniter