From 4e11ae0dd2fff25dc9f2f4f2a9f5a374ab4e5f26 Mon Sep 17 00:00:00 2001 From: juftin Date: Mon, 27 May 2024 22:18:29 -0600 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20persistent=20error=20notificatio?= =?UTF-8?q?ns?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- camply/config/notification_config.py | 2 +- camply/notifications/pushover.py | 17 +++++++++-------- camply/search/base_search.py | 5 ++++- 3 files changed, 14 insertions(+), 10 deletions(-) diff --git a/camply/config/notification_config.py b/camply/config/notification_config.py index 510b0665..5a169def 100644 --- a/camply/config/notification_config.py +++ b/camply/config/notification_config.py @@ -21,7 +21,7 @@ class PushoverConfig: """ PUSHOVER_API_ENDPOINT: str = "https://api.pushover.net/1/messages.json" - PUSHOVER_DEFAULT_API_TOKEN: bytes = b"YWpjN3M1a2hhYTRlOG1zYWhncnFnaHduZGdtbmI3" + PUSHOVER_DEFAULT_API_TOKEN: bytes = b"YXBqOWlzNjRrdm5zZWt3YmEyeDZxaDV0cWhxbXI5" API_HEADERS: dict = {"Content-Type": "application/json"} PUSH_TOKEN: str = getenv("PUSHOVER_PUSH_TOKEN", None) diff --git a/camply/notifications/pushover.py b/camply/notifications/pushover.py index 19bfd1d6..c8262985 100755 --- a/camply/notifications/pushover.py +++ b/camply/notifications/pushover.py @@ -34,6 +34,11 @@ def __init__(self, level: Optional[int] = logging.INFO): ) logger.error(warning_message) raise EnvironmentError(warning_message) + self.pushover_token = PushoverConfig.PUSH_TOKEN + if self.pushover_token in [None, ""]: + self.pushover_token = base64.b64decode( + PushoverConfig.PUSHOVER_DEFAULT_API_TOKEN + ).decode("utf-8") def send_message(self, message: str, **kwargs) -> requests.Response: """ @@ -47,17 +52,13 @@ def send_message(self, message: str, **kwargs) -> requests.Response: ------- requests.Response """ - token = ( - PushoverConfig.PUSH_TOKEN - if PushoverConfig.PUSH_TOKEN not in [None, ""] - else base64.b64decode(PushoverConfig.PUSHOVER_DEFAULT_API_TOKEN).decode( - "utf-8" - ) - ) response = self.session.post( url=PushoverConfig.PUSHOVER_API_ENDPOINT, params=dict( - token=token, user=PushoverConfig.PUSH_USER, message=message, **kwargs + token=self.pushover_token, + user=PushoverConfig.PUSH_USER, + message=message, + **kwargs, ), ) try: diff --git a/camply/search/base_search.py b/camply/search/base_search.py index 6a85b3a3..6b556c62 100644 --- a/camply/search/base_search.py +++ b/camply/search/base_search.py @@ -117,6 +117,7 @@ def __init__( AvailableCampsite ] = self.load_campsites_from_file() self.loaded_campsites: Set[AvailableCampsite] = self.campsites_found.copy() + self.search_attempts: int = 0 @property def search_days(self) -> List[datetime]: @@ -274,6 +275,7 @@ def _search_matching_campsites_available( ) logger.info(campsite_availability_message) raise CampsiteNotFoundError(campsite_availability_message) + self.search_attempts += 1 return matching_campgrounds @classmethod @@ -581,7 +583,8 @@ def get_matching_campsites( search_once=search_once, ) except Exception as e: - self.notifier.last_gasp(error=e) + if self.search_attempts >= 1: + self.notifier.last_gasp(error=e) raise e else: starting_count = len(self.campsites_found)