Added source for Hobsons Bay City Council. (#1616)

* Added source for Hobsons Bay City Council.

* reformatting

---------

Co-authored-by: 5ila5 <5ila5@users.noreply.github.com>
This commit is contained in:
Brett Errington
2024-01-03 02:02:28 +11:00
committed by GitHub
parent 19abf6195d
commit 3d5a6bffc2
5 changed files with 139 additions and 1 deletions

1
.gitignore vendored
View File

@@ -8,3 +8,4 @@ custom_components/waste_collection_schedule/waste_collection_schedule/test/secre
.DS_Store
.venv/
.idea/
.python-version

View File

@@ -40,6 +40,7 @@ Waste collection schedules in the following formats and countries are supported.
- [City of Onkaparinga Council](/doc/source/onkaparingacity_com.md) / onkaparingacity.com
- [Cumberland Council (NSW)](/doc/source/cumberland_nsw_gov_au.md) / cumberland.nsw.gov.au
- [Gold Coast City Council](/doc/source/goldcoast_qld_gov_au.md) / goldcoast.qld.gov.au
- [Hobsons Bay City Council](/doc/source/hobsonsbay_vic_gov_au.md) / hobsonsbay.vic.gov.au
- [Hume City Council](/doc/source/hume_vic_gov_au.md) / hume.vic.gov.au
- [Inner West Council (NSW)](/doc/source/innerwest_nsw_gov_au.md) / innerwest.nsw.gov.au
- [Ipswich City Council](/doc/source/ipswich_qld_gov_au.md) / ipswich.qld.gov.au

View File

@@ -0,0 +1,104 @@
import logging
from datetime import datetime
from urllib.parse import urlencode, urljoin
import requests
from waste_collection_schedule import Collection # type: ignore
TITLE = "Hobsons Bay City Council"
DESCRIPTION = "Source for Hobsons Bay City Council waste & recycling collection"
URL = "https://www.hobsonsbay.vic.gov.au"
TEST_CASES = {
"Civic Parade Medical Centre": {"street_address": "399 Queen St, Altona Meadows"},
"Hecho En Mexico Altona": {"street_address": "48 Pier St, Altona"},
}
API_URL = "https://hbcc-seven.vercel.app/api/"
SEARCH_API_URL = "https://jw7fda7yti-2.algolianet.com/1/indexes/*/queries"
SEARCH_APPLICATION_ID = "JW7FDA7YTI"
SEARCH_API_KEY = "7a3b39eba83ef97796c682e6a749be71"
ICON_MAP = {
"Rubbish": "mdi:trash-can-outline",
"Commingled Recycling": "mdi:recycle",
"Food and Garden": "mdi:leaf",
"Glass": "mdi:glass-fragile",
}
_LOGGER = logging.getLogger(__name__)
class Source:
def __init__(self, street_address: str):
self._street_address = street_address
def fetch(self):
_LOGGER.debug(f"Searching for address {self._street_address}")
search_params = {
"x-algolia-api-key": SEARCH_API_KEY,
"x-algolia-application-id": SEARCH_APPLICATION_ID,
}
# &query=&tagFilters=
search_data = {
"requests": [
{
"indexName": "addresses",
"params": urlencode(
{
"facets": [],
"highlightPostTag": "</ais-highlight-0000000000>",
"highlightPreTag": "<ais-highlight-0000000000>",
"hitsPerPage": 1, # no point in fetching more without a UI to select
"query": self._street_address,
"tagFilters": "",
}
),
}
]
}
search_response = requests.post(
SEARCH_API_URL, params=search_params, json=search_data
)
search_response.raise_for_status()
match = search_response.json()["results"][0]["hits"][0]
_LOGGER.debug(f"Search result: {match}")
asn = match["Assessment Number"]
_LOGGER.info(f"ASN: {asn}")
addresses_params = {"asn": asn}
addresses_endpoint = urljoin(API_URL, "addresses")
addresses_response = requests.get(addresses_endpoint, params=addresses_params)
addresses_response.raise_for_status()
address = addresses_response.json()["rows"][0]
day = address["day"]
area = address["area"]
_LOGGER.debug(f"Address result: {address}")
_LOGGER.info(f"Day: {day}, Area: {area}")
schedules_params = {"day": day, "area": area}
schedules_endpoint = urljoin(API_URL, "schedules")
schedules_response = requests.get(schedules_endpoint, params=schedules_params)
schedules_response.raise_for_status()
schedules = schedules_response.json()["rows"]
_LOGGER.debug(f"Schedules: {schedules}")
entries = [
Collection(
date=datetime.strptime(s["date"], "%d/%m/%Y").date(),
t=s["bin_type"],
icon=ICON_MAP.get(s["bin_type"], "Rubbish"),
)
for s in schedules
]
return entries

View File

@@ -0,0 +1,32 @@
# Hobsons Bay City Council
Support for schedules provided by [Hobsons Bay City Council](https://www.hobsonsbay.vic.gov.au).
## Configuration via configuration.yaml
```yaml
waste_collection_schedule:
sources:
- name: hobsonsbay_vic_gov_au
args:
street_address: STREET_ADDRESS
```
### Configuration Variables
**street_address**
*(string) (required)*
## Example
```yaml
waste_collection_schedule:
sources:
- name: hobsonsbay_vic_gov_au
args:
street_address: 399 Queen St, Altona Meadows
```
## How to get the source arguments
Visit the [Hobsons Bay City Council: When will my bins be collected?](https://www.hobsonsbay.vic.gov.au/Services/Waste-Recycling/When-will-my-bins-be-collected) page to install the iOS or Android app, then search for your address. The `street_address` argument should exactly match the street address shown in the autocomplete result of the app. If you do not want to install the app, you can also use the [interactive waste collections map](https://hbcc.maps.arcgis.com/apps/webappviewer/index.html?id=4db29582f74b4ba2ab2152fedeefe7b1) to search for a supported address. However, note that it does not always match what the API expects.

File diff suppressed because one or more lines are too long