Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 persistent error notifications #349

Merged
merged 1 commit into from
May 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion camply/config/notification_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@
"""

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"}

Check failure on line 25 in camply/config/notification_config.py

View workflow job for this annotation

GitHub Actions / lint

Missing type parameters for generic type "dict" [type-arg]

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

Check failure on line 27 in camply/config/notification_config.py

View workflow job for this annotation

GitHub Actions / lint

Argument 2 to "getenv" has incompatible type "None"; expected "str" [arg-type]
PUSH_USER: str = getenv("PUSHOVER_PUSH_USER", None)

Check failure on line 28 in camply/config/notification_config.py

View workflow job for this annotation

GitHub Actions / lint

Argument 2 to "getenv" has incompatible type "None"; expected "str" [arg-type]


class AppriseConfig:
Expand All @@ -33,7 +33,7 @@
Apprise Notification Config Class
"""

APPRISE_URL: str = getenv("APPRISE_URL", None)

Check failure on line 36 in camply/config/notification_config.py

View workflow job for this annotation

GitHub Actions / lint

Argument 2 to "getenv" has incompatible type "None"; expected "str" [arg-type]


class EmailConfig:
Expand Down Expand Up @@ -81,7 +81,7 @@
"""

PUSHBULLET_API_ENDPOINT: str = "https://api.pushbullet.com/v2/pushes"
API_HEADERS: dict = {"Content-Type": "application/json"}

Check failure on line 84 in camply/config/notification_config.py

View workflow job for this annotation

GitHub Actions / lint

Missing type parameters for generic type "dict" [type-arg]

API_TOKEN = getenv("PUSHBULLET_API_TOKEN", None)

Expand Down
17 changes: 9 additions & 8 deletions camply/notifications/pushover.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
"""
Expand All @@ -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:
Expand Down
5 changes: 4 additions & 1 deletion camply/search/base_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -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]:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down
Loading