Skip to content

Commit

Permalink
Return before sending when no urls (#187)
Browse files Browse the repository at this point in the history
cal4 authored Aug 25, 2024
2 parents 54e00cb + c70155a commit 0a94091
Showing 3 changed files with 25 additions and 1 deletion.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -5,6 +5,12 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [1.0.1] - 2024-08-25

### Fixed

- [AssertionError from apprise.notify(title=str(title), body=str(body))](https://github.com/klept0/MS-Rewards-Farmer/issues)

## [1.0.0] - 2024-08-23

### Removed
9 changes: 8 additions & 1 deletion src/utils.py
Original file line number Diff line number Diff line change
@@ -46,7 +46,11 @@ def loadConfig(configFilename="config.yaml") -> dict:
configFile = Utils.getProjectRoot() / configFilename
try:
with open(configFile, "r") as file:
return yaml.safe_load(file)
config = yaml.safe_load(file)
if not config:
logging.info(f"{file} doesn't exist")
return {}
return config
except OSError:
logging.warning(f"{configFilename} doesn't exist")
return {}
@@ -57,6 +61,9 @@ def sendNotification(title, body) -> None:
return
apprise = Apprise()
urls: list[str] = Utils.loadConfig("config-private.yaml").get("apprise", {}).get("urls", [])
if not urls:
logging.debug("No urls found, not sending notification")
return
for url in urls:
apprise.add(url)
assert apprise.notify(title=str(title), body=str(body))
11 changes: 11 additions & 0 deletions test/test_utils.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
from argparse import Namespace
from unittest import TestCase

from src.utils import Utils


class TestUtils(TestCase):
def test_send_notification(self):
Utils.args = Namespace()
Utils.args.disable_apprise = False
Utils.sendNotification("title", "body")

0 comments on commit 0a94091

Please sign in to comment.