Planning/backend/planning/notifications.py
Louis Mazin 6a18a3caff clean
2026-10-02 17:10:37 +02:00

27 lines
722 B
Python

import os
import urllib.error
import urllib.request
def send_ntfy_notification(title, message, click_url=None):
server = os.getenv('NTFY_SERVER', '').rstrip('/')
topic = os.getenv('NTFY_TOPIC', '').strip()
if not server or not topic:
return False
request = urllib.request.Request(
f'{server}/{topic}',
data=message.encode('utf-8'),
method='POST',
)
request.add_header('Title', title)
request.add_header('Tags', 'calendar,question')
if click_url:
request.add_header('Click', click_url)
try:
with urllib.request.urlopen(request, timeout=5):
return True
except (urllib.error.URLError, TimeoutError):
return False