feat: stuur WhatsApp notificatie na dashcam transfer
This commit is contained in:
parent
caac864241
commit
e0b36a5b9c
2 changed files with 98 additions and 3 deletions
|
|
@ -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__":
|
||||
|
|
|
|||
Loading…
Reference in a new issue