diff options
| -rw-r--r-- | scripts/heartbeat.py | 9 |
1 files changed, 6 insertions, 3 deletions
diff --git a/scripts/heartbeat.py b/scripts/heartbeat.py index 062cecb..5fe321b 100644 --- a/scripts/heartbeat.py +++ b/scripts/heartbeat.py @@ -12,7 +12,7 @@ import subprocess import sys import urllib.request from email.header import Header -from datetime import datetime, timedelta, timezone +from datetime import time, datetime, timedelta, timezone from pathlib import Path # ---------- config ---------- @@ -22,7 +22,8 @@ STATE_DIR = Path("/etc/senia/data/heartbeat") LAST_WAKE_FILE = STATE_DIR / "last_wake_at" WORKSPACE = Path("/workspace") -QUIET_MAX_HOURS = 4 +QUIET_MIN_HOURS = 2.5 +QUIET_MAX_HOURS = QUIET_MIN_HOURS * 2 NTFY_URL = os.environ["NTFY_URL"] # e.g. https://ntfy.example.tld/senia NTFY_TOKEN = os.environ["NTFY_TOKEN"] @@ -63,7 +64,9 @@ def should_wake(tasks, last_wake, now) -> tuple[bool, str]: if last_wake is None: return True, "First wake-up since the script was set up." elapsed = now - last_wake - if elapsed >= timedelta(hours=QUIET_MAX_HOURS): + now = datetime.now().time() + quiet_hours = QUIET_MAX_HOURS if (now >= time(22) or now < time(7)) else QUIET_MIN_HOURS + if elapsed >= timedelta(hours=quiet_hours): hrs = elapsed.total_seconds() / 3600 return True, f"It's been {hrs:.1f} hours since the last check-in." return False, "" |
