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