From e0b36a5b9cdc1d95ba3a71c1b36388851c755395 Mon Sep 17 00:00:00 2001 From: Eddy de Vink Date: Sun, 7 Jun 2026 16:18:43 +0200 Subject: [PATCH] feat: stuur WhatsApp notificatie na dashcam transfer --- dashcam-transfer.py | 31 +++++++- .../plans/2026-06-07-whatsapp-notification.md | 70 +++++++++++++++++++ 2 files changed, 98 insertions(+), 3 deletions(-) create mode 100644 docs/superpowers/plans/2026-06-07-whatsapp-notification.md diff --git a/dashcam-transfer.py b/dashcam-transfer.py index 3fcde30..c62465f 100644 --- a/dashcam-transfer.py +++ b/dashcam-transfer.py @@ -3,12 +3,14 @@ import argparse import fcntl +import json import logging import os import re import shutil import subprocess import sys +import urllib.request SD_CARD = "/mnt/sdcard" SOURCE_DIR = os.path.join(SD_CARD, "Novatek", "Movie") @@ -103,6 +105,30 @@ def ensure_free_space(needed_bytes, target_base): logging.info("Ruimte vrijgemaakt: %d bytes door %d mappen", freed, len(removed)) +WHATSAPP_API = "http://100.97.199.84:3000/client/sendMessage/EdGpt" +WHATSAPP_CHAT = "31620248011@c.us" + + +def send_whatsapp_notification(ok, errors): + if errors == 0: + prefix = "✅" + status = "geen fouten" + else: + prefix = "❌" + status = f"{errors} fout(en)" + body = f"{prefix} Dashcam transfer voltooid: {ok} bestanden overgezet, {status}" + payload = {"chatId": WHATSAPP_CHAT, "content": body, "contentType": "string"} + try: + data = json.dumps(payload).encode() + req = urllib.request.Request( + WHATSAPP_API, data=data, headers={"Content-Type": "application/json"} + ) + urllib.request.urlopen(req, timeout=10) + logging.info("WhatsApp notificatie verstuurd") + except Exception as e: + logging.warning("WhatsApp notificatie mislukt: %s", e) + + def parse_args(): parser = argparse.ArgumentParser(description="Dashcam transfer tool") parser.add_argument( @@ -186,9 +212,8 @@ def main(): ) ok += 1 - logging.info( - "Transfer voltooid: %d ok, %d fouten", ok, errors - ) + logging.info("Transfer voltooid: %d ok, %d fouten", ok, errors) + send_whatsapp_notification(ok, errors) if __name__ == "__main__": diff --git a/docs/superpowers/plans/2026-06-07-whatsapp-notification.md b/docs/superpowers/plans/2026-06-07-whatsapp-notification.md new file mode 100644 index 0000000..671432a --- /dev/null +++ b/docs/superpowers/plans/2026-06-07-whatsapp-notification.md @@ -0,0 +1,70 @@ +# WhatsApp Notification Implementation Plan + +> **For agentic workers:** REQUIRED SUB-SKILL: Use superpowers:subagent-driven-development (recommended) or superpowers:executing-plans to implement this plan task-by-task. Steps use checkbox (`- [ ]`) syntax for tracking. + +**Goal:** Add a WhatsApp notification to the dashcam transfer script that sends a summary to admin Eddy after each transfer. + +**Architecture:** A single `send_whatsapp_notification()` function is added to `dashcam-transfer.py`. It POSTs to the local wwebjs-api (running on Mac Mini via Tailscale) using stdlib `urllib.request`. Failures are logged but never crash the script. + +**Tech Stack:** Python 3 stdlib (`urllib.request`, `json`), wwebjs-api REST API + +--- + +### Task 1: Add WhatsApp notification to dashcam-transfer.py + +**Files:** +- Modify: `dashcam-transfer.py:3` (add imports) +- Modify: `dashcam-transfer.py:189-191` (add notification call) + +- [ ] **Step 1: Add imports** + +Add `import json` and `import urllib.request` after the existing stdlib imports. + +- [ ] **Step 2: Add `send_whatsapp_notification()` function** + +Insert before `parse_args()` (after `ensure_free_space`): + +```python +WHATSAPP_API = "http://100.97.199.84:3000/client/sendMessage/EdGpt" +WHATSAPP_CHAT = "31620248011@c.us" + + +def send_whatsapp_notification(ok, errors): + status = "geen fouten" if errors == 0 else f"{errors} fout(en)" + body = f"Dashcam transfer voltooid: {ok} bestanden overgezet, {status}" + payload = {"chatId": WHATSAPP_CHAT, "content": body, "contentType": "string"} + try: + data = json.dumps(payload).encode() + req = urllib.request.Request(WHATSAPP_API, data=data, headers={"Content-Type": "application/json"}) + urllib.request.urlopen(req, timeout=10) + logging.info("WhatsApp notificatie verstuurd") + except Exception as e: + logging.warning("WhatsApp notificatie mislukt: %s", e) +``` + +- [ ] **Step 3: Call notification at end of `main()`** + +Replace: +```python + logging.info( + "Transfer voltooid: %d ok, %d fouten", ok, errors + ) +``` + +With: +```python + logging.info("Transfer voltooid: %d ok, %d fouten", ok, errors) + send_whatsapp_notification(ok, errors) +``` + +- [ ] **Step 4: Verify the script parses correctly** + +Run: `python3 -c "import ast; ast.parse(open('dashcam-transfer.py').read()); print('OK')"` +Expected: `OK` + +- [ ] **Step 5: Commit** + +```bash +git add dashcam-transfer.py +git commit -m "feat: stuur WhatsApp notificatie na dashcam transfer" +```