Skip to content

Commit 4e11ae0

Browse files
committedMay 28, 2024
🐛 persistent error notifications
1 parent 6164d0f commit 4e11ae0

File tree

3 files changed

+14
-10
lines changed

3 files changed

+14
-10
lines changed
 

‎camply/config/notification_config.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class PushoverConfig:
2121
"""
2222

2323
PUSHOVER_API_ENDPOINT: str = "https://api.pushover.net/1/messages.json"
24-
PUSHOVER_DEFAULT_API_TOKEN: bytes = b"YWpjN3M1a2hhYTRlOG1zYWhncnFnaHduZGdtbmI3"
24+
PUSHOVER_DEFAULT_API_TOKEN: bytes = b"YXBqOWlzNjRrdm5zZWt3YmEyeDZxaDV0cWhxbXI5"
2525
API_HEADERS: dict = {"Content-Type": "application/json"}
2626

2727
PUSH_TOKEN: str = getenv("PUSHOVER_PUSH_TOKEN", None)

‎camply/notifications/pushover.py

+9-8
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ def __init__(self, level: Optional[int] = logging.INFO):
3434
)
3535
logger.error(warning_message)
3636
raise EnvironmentError(warning_message)
37+
self.pushover_token = PushoverConfig.PUSH_TOKEN
38+
if self.pushover_token in [None, ""]:
39+
self.pushover_token = base64.b64decode(
40+
PushoverConfig.PUSHOVER_DEFAULT_API_TOKEN
41+
).decode("utf-8")
3742

3843
def send_message(self, message: str, **kwargs) -> requests.Response:
3944
"""
@@ -47,17 +52,13 @@ def send_message(self, message: str, **kwargs) -> requests.Response:
4752
-------
4853
requests.Response
4954
"""
50-
token = (
51-
PushoverConfig.PUSH_TOKEN
52-
if PushoverConfig.PUSH_TOKEN not in [None, ""]
53-
else base64.b64decode(PushoverConfig.PUSHOVER_DEFAULT_API_TOKEN).decode(
54-
"utf-8"
55-
)
56-
)
5755
response = self.session.post(
5856
url=PushoverConfig.PUSHOVER_API_ENDPOINT,
5957
params=dict(
60-
token=token, user=PushoverConfig.PUSH_USER, message=message, **kwargs
58+
token=self.pushover_token,
59+
user=PushoverConfig.PUSH_USER,
60+
message=message,
61+
**kwargs,
6162
),
6263
)
6364
try:

‎camply/search/base_search.py

+4-1
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ def __init__(
117117
AvailableCampsite
118118
] = self.load_campsites_from_file()
119119
self.loaded_campsites: Set[AvailableCampsite] = self.campsites_found.copy()
120+
self.search_attempts: int = 0
120121

121122
@property
122123
def search_days(self) -> List[datetime]:
@@ -274,6 +275,7 @@ def _search_matching_campsites_available(
274275
)
275276
logger.info(campsite_availability_message)
276277
raise CampsiteNotFoundError(campsite_availability_message)
278+
self.search_attempts += 1
277279
return matching_campgrounds
278280

279281
@classmethod
@@ -581,7 +583,8 @@ def get_matching_campsites(
581583
search_once=search_once,
582584
)
583585
except Exception as e:
584-
self.notifier.last_gasp(error=e)
586+
if self.search_attempts >= 1:
587+
self.notifier.last_gasp(error=e)
585588
raise e
586589
else:
587590
starting_count = len(self.campsites_found)

0 commit comments

Comments
 (0)
Failed to load comments.