mirror of
https://github.com/sascha-hemi/hacs_waste_collection_schedule.git
synced 2026-03-21 05:06:33 +01:00
add striling_wa_gov_au
This commit is contained in:
@@ -91,6 +91,7 @@ If your service provider is not listed, feel free to open a [source request issu
|
||||
- [Singleton Council](/doc/source/impactapps_com_au.md) / singleton.nsw.gov.au
|
||||
- [Snowy Valleys Council](/doc/source/impactapps_com_au.md) / snowyvalleys.nsw.gov.au
|
||||
- [South Burnett Regional Council](/doc/source/impactapps_com_au.md) / southburnett.qld.gov.au
|
||||
- [Stirling](/doc/source/stirling_wa_gov_au.md) / stirling.wa.gov.au
|
||||
- [Stonnington City Council](/doc/source/stonnington_vic_gov_au.md) / stonnington.vic.gov.au
|
||||
- [The Hawkesbury City Council, Sydney](/doc/source/hawkesbury_nsw_gov_au.md) / hawkesbury.nsw.gov.au
|
||||
- [The Hills Shire Council, Sydney](/doc/source/thehills_nsw_gov_au.md) / thehills.nsw.gov.au
|
||||
|
||||
@@ -348,6 +348,11 @@
|
||||
"service": "South Burnett Regional Council"
|
||||
}
|
||||
},
|
||||
{
|
||||
"title": "Stirling",
|
||||
"module": "stirling_wa_gov_au",
|
||||
"default_params": {}
|
||||
},
|
||||
{
|
||||
"title": "Stonnington City Council",
|
||||
"module": "stonnington_vic_gov_au",
|
||||
|
||||
@@ -0,0 +1,82 @@
|
||||
import logging
|
||||
|
||||
import requests
|
||||
from dateutil import parser
|
||||
from waste_collection_schedule import Collection # type: ignore[attr-defined]
|
||||
|
||||
_LOGGER = logging.getLogger(__name__)
|
||||
|
||||
TITLE = "Stirling"
|
||||
DESCRIPTION = "Source for Stirling."
|
||||
URL = "https://www.stirling.wa.gov.au/"
|
||||
TEST_CASES = {
|
||||
"-31.9034183 115.8320855": {"lat": -31.9034183, "lon": 115.8320855},
|
||||
"-31.878331, 115.815553": {"lat": "-31.8783052", "lon": "115.8157741"},
|
||||
}
|
||||
|
||||
|
||||
ICON_MAP = {
|
||||
"red": "mdi:trash-can",
|
||||
"green": "mdi:leaf",
|
||||
"greenverge": "mdi:pine-tree",
|
||||
"yellow": "mdi:recycle",
|
||||
}
|
||||
|
||||
|
||||
API_URL = "https://www.stirling.wa.gov.au/aapi/map"
|
||||
|
||||
|
||||
class Source:
|
||||
def __init__(self, lat: float, lon: float):
|
||||
if isinstance(lat, str):
|
||||
lat = float(lat)
|
||||
if isinstance(lon, str):
|
||||
lon = float(lon)
|
||||
|
||||
self._lat: float = lat
|
||||
self._lon: float = lon
|
||||
|
||||
def fetch(self) -> list[Collection]:
|
||||
headers = {
|
||||
"Host": "www.stirling.wa.gov.au",
|
||||
"Accept": "application/json, text/javascript, */*; q=0.01",
|
||||
"configid": "7c833520-7b62-4228-8522-fb1a220b32e8",
|
||||
"form": "57753bab-f589-44d7-8934-098b6d5c572f",
|
||||
"fields": f"{self._lon},{self._lat}",
|
||||
"apikeylookup": "Test Map Key",
|
||||
"X-Requested-With": "XMLHttpRequest",
|
||||
"Connection": "keep-alive",
|
||||
}
|
||||
r = requests.get(API_URL, headers=headers)
|
||||
r.raise_for_status()
|
||||
|
||||
data = r.json()
|
||||
entries = []
|
||||
for collection in data:
|
||||
bin_type = None
|
||||
bin_date_str = None
|
||||
bin_date = None
|
||||
|
||||
for arg in collection:
|
||||
if arg.get("name") == "type":
|
||||
bin_type = arg.get("value")
|
||||
if arg.get("name") == "date":
|
||||
bin_date_str = arg.get("value")
|
||||
if not isinstance(bin_date_str, str):
|
||||
continue
|
||||
bin_date_str = bin_date_str.replace(" ", " ").strip()
|
||||
try:
|
||||
# Aug 7 2024
|
||||
bin_date = parser.parse(bin_date_str).date()
|
||||
except ValueError:
|
||||
_LOGGER.warning("Could not parse date %s", bin_date_str)
|
||||
|
||||
if bin_date is None:
|
||||
_LOGGER.warning("Could not find date for collection %s", bin_type)
|
||||
continue
|
||||
if bin_type is None:
|
||||
_LOGGER.warning("Skipping invalid collection record")
|
||||
continue
|
||||
icon = ICON_MAP.get(bin_type.lower()) # Collection icon
|
||||
entries.append(Collection(date=bin_date, t=bin_type, icon=icon))
|
||||
return entries
|
||||
46
doc/source/stirling_wa_gov_au.md
Normal file
46
doc/source/stirling_wa_gov_au.md
Normal file
@@ -0,0 +1,46 @@
|
||||
# Stirling
|
||||
|
||||
Support for schedules provided by [Stirling](https://www.stirling.wa.gov.au/), serving Stirling, Australia.
|
||||
|
||||
## Configuration via configuration.yaml
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: stirling_wa_gov_au
|
||||
args:
|
||||
lat: LATITUDE
|
||||
lon: LONGITUDE
|
||||
|
||||
```
|
||||
|
||||
### Configuration Variables
|
||||
|
||||
**lat**
|
||||
*(Float) (required)*
|
||||
|
||||
**lon**
|
||||
*(Float) (required)*
|
||||
|
||||
## Example
|
||||
|
||||
```yaml
|
||||
waste_collection_schedule:
|
||||
sources:
|
||||
- name: stirling_wa_gov_au
|
||||
args:
|
||||
lat: -31.9034183
|
||||
lon: 115.8320855
|
||||
|
||||
```
|
||||
|
||||
## How to get the source argument
|
||||
|
||||
### Using your address coordinates
|
||||
|
||||
1. Find the coordinates of your address using any map service like Google Maps. (the coordinates should be in decimal format with 7 decimal places)
|
||||
2. Write the coordinates in the configuration file.
|
||||
|
||||
### Inspecting network requests of the Stirling website
|
||||
|
||||
Visit <https://www.stirling.wa.gov.au/waste-and-environment/waste-and-recycling/residential-bin-collections> and open the developer tools of your browser. Go to the network tab and filter. search for your address in the websites search bar and click on you address. In your network tab look for a GET request to https://www.stirling.wa.gov.au/aapi/map. Click on that request and look for the Request Headers. The `fields` value of the Request Headers is latitude and longitude **in inverse order!!!** (longitude,latitude). Write the coordinates in the configuration file.
|
||||
Reference in New Issue
Block a user