From 21511c669cae5a2d564cf6b6df1bcd46e24a625d Mon Sep 17 00:00:00 2001 From: Jan-Henrik Bruhn Date: Wed, 8 Feb 2023 22:52:52 +0100 Subject: [PATCH] Use croniter --- screenshotter/config.yaml | 2 +- screenshotter/rootfs/app/app.py | 8 ++++++-- screenshotter/rootfs/app/config.yaml | 2 +- screenshotter/rootfs/app/requirements.txt | 1 + 4 files changed, 9 insertions(+), 4 deletions(-) diff --git a/screenshotter/config.yaml b/screenshotter/config.yaml index 35d41fb..c650084 100644 --- a/screenshotter/config.yaml +++ b/screenshotter/config.yaml @@ -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 diff --git a/screenshotter/rootfs/app/app.py b/screenshotter/rootfs/app/app.py index 7255228..316d56a 100644 --- a/screenshotter/rootfs/app/app.py +++ b/screenshotter/rootfs/app/app.py @@ -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) diff --git a/screenshotter/rootfs/app/config.yaml b/screenshotter/rootfs/app/config.yaml index e24bffb..b88a88c 100644 --- a/screenshotter/rootfs/app/config.yaml +++ b/screenshotter/rootfs/app/config.yaml @@ -1,4 +1,4 @@ images: - name: "001100" url: https://ha.baubs.net/lovelace-teflons/0?kiosk - period_minutes: 1 + cron: "*/5 * * * *" diff --git a/screenshotter/rootfs/app/requirements.txt b/screenshotter/rootfs/app/requirements.txt index 9c38586..9e8fae1 100644 --- a/screenshotter/rootfs/app/requirements.txt +++ b/screenshotter/rootfs/app/requirements.txt @@ -1,3 +1,4 @@ selenium Pillow pyyaml +croniter