Skip to content

Commit

Permalink
raise error instad of returning [] + Reformatting
Browse files Browse the repository at this point in the history
  • Loading branch information
5ila5 committed Nov 6, 2023
1 parent 1bc8263 commit 3aa1e20
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import requests
from bs4 import BeautifulSoup
from requests.utils import requote_uri
from waste_collection_schedule import Collection
from waste_collection_schedule import Collection # type: ignore[attr-defined]

TITLE = "Blacktown City Council (NSW)"
DESCRIPTION = "Source for Blacktown City Council rubbish collection."
Expand Down Expand Up @@ -48,6 +48,7 @@
"Recycling": "mdi:recycle",
}


class Source:
def __init__(
self, post_code: str, suburb: str, street_name: str, street_number: str
Expand Down Expand Up @@ -77,7 +78,9 @@ def fetch(self):
break

if locationId == 0:
return []
raise ValueError(
f"Unable to find location ID for {address}, maybe you misspelled your address?"
)

# Retrieve the upcoming collections for our property
q = requote_uri(str(API_URLS["collection"]).format(locationId))
Expand All @@ -96,13 +99,15 @@ def fetch(self):
for item in services:
# test if <div> contains a valid date. If not, is is not a collection item.
date_text = item.find("div", attrs={"class": "next-service"})

# The date format currently used on https://www.blacktown.nsw.gov.au/Services/Waste-services-and-collection/Waste-collection-days
date_format = '%a %d/%m/%Y'
date_format = "%a %d/%m/%Y"

try:
# Strip carriage returns and newlines out of the HTML content
cleaned_date_text = date_text.text.replace('\r','').replace('\n','').strip()
cleaned_date_text = (
date_text.text.replace("\r", "").replace("\n", "").strip()
)

# Parse the date
date = datetime.datetime.strptime(cleaned_date_text, date_format).date()
Expand Down
1 change: 1 addition & 0 deletions doc/source/blacktown_nsw_gov_au.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ waste_collection_schedule:
Visit the [Blacktown City Council Waste Collection Days](https://www.blacktown.nsw.gov.au/Services/Waste-services-and-collection/Waste-collection-days) page, follow the quick link to *Check my collection day*, and search for your address. The street address arguments used to configure hacs_waste_collection_schedule should exactly match the street address shown in the autocomplete result.
## How this integration uses Blacktown Council's APIs
Two API calls are currently needed to retrieve waste collection schedule results from Blacktown Council:
1. The address search API at https://www.blacktown.nsw.gov.au/api/v1/myarea/search
2. The waste services API at https://www.blacktown.nsw.gov.au/ocapi/Public/myarea/wasteservices
Expand Down

0 comments on commit 3aa1e20

Please sign in to comment.