From fcd227e3ede77a8c5469bb4bfd9701875ba088a2 Mon Sep 17 00:00:00 2001 From: kbe Date: Mon, 21 Jul 2025 21:32:05 +0200 Subject: [PATCH] feat: ENV var to toggle impossible notification --- .env.example | 1 + session_notifier.py | 18 +++++++++++++++++- 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/.env.example b/.env.example index d321bec..a23c56a 100644 --- a/.env.example +++ b/.env.example @@ -5,6 +5,7 @@ CROSSFIT_PASSWORD=your_password # Notification settings ENABLE_EMAIL_NOTIFICATIONS=true ENABLE_TELEGRAM_NOTIFICATIONS=true +NOTIFY_IMPOSSIBLE_BOOKING=false # Email notification credentials SMTP_SERVER=mail.infomaniak.com diff --git a/session_notifier.py b/session_notifier.py index 626a6d2..951d3bf 100644 --- a/session_notifier.py +++ b/session_notifier.py @@ -34,6 +34,9 @@ class SessionNotifier: self.enable_email = enable_email self.enable_telegram = enable_telegram + # Check environment variable for impossible booking notifications + self.notify_impossible = os.environ.get("NOTIFY_IMPOSSIBLE_BOOKING", "true").lower() in ("true", "1", "yes") + def send_email_notification(self, message): """ Send an email notification with the given message. @@ -121,13 +124,26 @@ class SessionNotifier: if self.enable_telegram: await self.send_telegram_notification(telegram_message) - async def notify_impossible_booking(self, session_details): + async def notify_impossible_booking(self, session_details, notify_if_impossible=None): """ Notify about an impossible session booking via email and Telegram. Args: session_details (str): Details about the session that couldn't be booked + notify_if_impossible (bool, optional): Whether to send notifications for impossible bookings. + If None, uses the value from the NOTIFY_IMPOSSIBLE_BOOKING + environment variable. """ + # Determine if notifications should be sent + # First check the method parameter (if provided), then the environment variable + should_notify = ( + notify_if_impossible if notify_if_impossible is not None else self.notify_impossible + ) + + # Only proceed if notifications for impossible bookings are enabled + if not should_notify: + return + # Create messages for both email and Telegram email_message = f"Failed to book session: {session_details}" telegram_message = f"Failed to book session: {session_details}" -- 2.49.1