Skip to content

Commit

Permalink
making notifications little more exciting #5
Browse files Browse the repository at this point in the history
  • Loading branch information
joe-mccarthy committed Sep 20, 2024
1 parent 1d102bd commit 9819831
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
22 changes: 13 additions & 9 deletions src/app/bindicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,27 +25,31 @@ def run(self):
collection_date = collections[0].date
bin_type = collections[0].wheelie.bin_type
if today == collection_date:
message = (
f"Bin collection is today for {bin_type}"
)
message = f"Bin collection is today for {bin_type}"
logging.info(message)
logging.info(f"Publishing message to ntfy.sh")
requests.post(
f"https://ntfy.sh/{self.topic}",
data=message.encode(encoding="utf-8"),
headers={
"Title": "Binday Today",
"Priority": "3",
"Tags": "rotating_light",
},
)
elif tomorrow == collection_date:
message = (
f"Bin collection is tomorrow for {bin_type}"
)
message = f"Bin collection is tomorrow for {bin_type}"
logging.info(message)
logging.info(f"Publishing message to ntfy.sh")
requests.post(
f"https://ntfy.sh/{self.topic}",
data=message.encode(encoding="utf-8"),
headers={
"Title": "Binday Tomorrow",
"Priority": "3",
"Tags": "warning",
},
)
else:
logging.info("No bin collection today")
logging.info(
f"Next bin collection is {collection_date}, {bin_type}"
)
logging.info(f"Next bin collection is {collection_date}, {bin_type}")
20 changes: 17 additions & 3 deletions tests/test_bindicator.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,24 @@ def test_bindicator_run_collections(mock_requests, mock_api):
mock_requests.post.assert_called_once_with(
"https://ntfy.sh/topic",
data=f"Bin collection is today for {collection_date.wheelie.bin_type}".encode(
encoding="utf-8"
encoding="utf-8",
),
headers={
"Title": "Binday Today",
"Priority": "3",
"Tags": "rotating_light",
},
)


@patch("src.app.bindicator.Api")
@patch("src.app.bindicator.requests")
def test_bincollection_tomorrow(mock_requests, mock_api):
bindicator = Bindicator("uprn", "topic")
today = date.today()
collection = Collection("recycling", (today + timedelta(days=1)).strftime("%d/%m/%Y"))
collection = Collection(
"recycling", (today + timedelta(days=1)).strftime("%d/%m/%Y")
)
collection_date = CollectionDate(collection)
mock_api().get_data.return_value = [collection_date]

Expand All @@ -55,10 +63,16 @@ def test_bincollection_tomorrow(mock_requests, mock_api):
mock_requests.post.assert_called_once_with(
"https://ntfy.sh/topic",
data=f"Bin collection is tomorrow for {collection_date.wheelie.bin_type}".encode(
encoding="utf-8"
encoding="utf-8",
),
headers={
"Title": "Binday Tomorrow",
"Priority": "3",
"Tags": "warning",
},
)


@patch("src.app.bindicator.Api")
@patch("src.app.bindicator.requests")
def test_no_collection_today(mock_requests, mock_api):
Expand Down

0 comments on commit 9819831

Please sign in to comment.