42 lines
1.2 KiB
Python
Executable File
42 lines
1.2 KiB
Python
Executable File
#!/usr/bin/env python3
|
|
"""Send the Reyna family wind-down reminder to the WhatsApp group without cron wrappers."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import urllib.request
|
|
|
|
CHAT_ID = "120363424746547296@g.us"
|
|
BRIDGE_URL = "http://127.0.0.1:3000/send"
|
|
MESSAGE = (
|
|
"Family wind-down time: read a bedtime story, say the bedtime prayer, "
|
|
"get teeth brushed, tidy one small thing, and settle in for the night."
|
|
)
|
|
|
|
|
|
def send_whatsapp(message: str) -> None:
|
|
payload = json.dumps({"chatId": CHAT_ID, "message": message}).encode("utf-8")
|
|
req = urllib.request.Request(
|
|
BRIDGE_URL,
|
|
data=payload,
|
|
headers={"Content-Type": "application/json"},
|
|
method="POST",
|
|
)
|
|
with urllib.request.urlopen(req, timeout=30) as resp:
|
|
body = resp.read().decode("utf-8", errors="replace")
|
|
if resp.status != 200:
|
|
raise RuntimeError(f"WhatsApp bridge returned HTTP {resp.status}: {body}")
|
|
|
|
|
|
def main() -> int:
|
|
try:
|
|
send_whatsapp(MESSAGE)
|
|
return 0
|
|
except Exception as exc:
|
|
print(f"Family wind-down WhatsApp send failed: {exc}", file=sys.stderr)
|
|
return 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|