実装例 — pc_mesh.py
3PC 通知の実装 (Python 標準ライブラリのみ)
def send(target, message):
topic = f"{MESH_SECRET}-{target}"
url = f"https://ntfy.sh/{topic}"
req = Request(url, data=message.encode(), method="POST")
req.add_header("Title", f"[cockpit] Cockpit (Mac)")
req.add_header("Tags", "airplane,cockpit")
urlopen(req, timeout=10)
def read_messages(limit=5, since="12h"):
topic = f"{MESH_SECRET}-{_get_node()}"
url = f"https://ntfy.sh/{topic}/json?poll=1&since={since}"
resp = urlopen(Request(url), timeout=10)
return [json.loads(l) for l in resp.read().decode().split("\n") if l]
依存ライブラリ: ゼロ (urllib は Python 標準)