authoravatarclover caruso<git@paperclover.net>2026-11-22 00:12:20-08:00
committeravatarclover caruso<git@paperclover.net>2026-11-22 03:33:00-08:00
log1e32e2ab9fc916bbdefd5efe7a151e083345c19f
tree959aaae00a9fb0378b2f81c658fec02ddea268d7
parent8ef31a67af6341ab217275f11548130c36a80ba2
signature Signed by SSH key SHA256:52mNGHRsVFBDED9IAX5pe+LRWUefqTbxEReunq21QvU

send webhook


1 files changed, 26 insertions(+), 0 deletions(-)

tools/send-webhook.py created+26
...@@ -0,0 +1,26 @@
1#!/usr/bin/env python3
2"""Post a message to a Discord-style webhook.
3
4usage: send-webhook.py URL_FILE [MESSAGE...] (message from stdin when omitted)
5
6The URL carries the token, so it is read from a private file, never argv.
7"""
8import json
9import sys
10import urllib.request
11from pathlib import Path
12
13if len(sys.argv) < 2:
14 sys.exit(__doc__)
15url = Path(sys.argv[1]).read_text().strip()
16content = " ".join(sys.argv[2:]) or sys.stdin.read().strip()
17if not content:
18 sys.exit("empty message")
19
20request = urllib.request.Request(
21 url,
22 json.dumps({"content": content}).encode(),
23 {"Content-Type": "application/json", "User-Agent": "snowglobe-webhook/1.0"},
24)
25with urllib.request.urlopen(request, timeout=10) as response:
26 print(response.status)