Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add striling_wa_gov_au #2378

Merged
merged 1 commit into from
Aug 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions custom_components/waste_collection_schedule/sources.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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 changes: 46 additions & 0 deletions doc/source/stirling_wa_gov_au.md
Original file line number Diff line number Diff line change
@@ -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.
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Waste collection schedules from service provider web sites are updated daily, de
|--|--|
| Generic | ICS / iCal files |
| Static | User-defined dates or repeating date patterns |<!--Begin of country section-->
| Australia | Armadale (Western Australia), Australian Capital Territory (ACT), Banyule City Council, Baw Baw Shire Council, Bayside City Council, Bega Valley Shire Council, Belmont City Council, Blacktown City Council (NSW), Blue Mountains City Council, Brisbane City Council, Burwood City Council, Campbelltown City Council (NSW), Cardinia Shire Council, City of Ballarat, City of Canada Bay Council, City of Cockburn, City of Darebin, City of Greater Geelong, City of Kingston, City of Onkaparinga Council, Cowra Council, Cumberland Council (NSW), Forbes Shire Council, Frankston City Council, Gold Coast City Council, Gwydir Shire Council, Hobsons Bay City Council, Hornsby Shire Council, Hume City Council, Impact Apps, Inner West Council (NSW), Ipswich City Council, Knox City Council, Ku-ring-gai Council, Lake Macquarie City Council, Lithgow City Council, Livingstone Shire Council, Loddon Shire Council, Logan City Council, Macedon Ranges Shire Council, Mansfield Shire Council, Maribyrnong Council, Maroondah City Council, Melton City Council, Merri-bek City Council, Moira Shire Council, Moree Plains Shire Council, Moreton Bay, Mosman Council, Nillumbik Shire Council, North Adelaide Waste Management Authority, Penrith City Council, Port Adelaide Enfield, South Australia, Port Macquarie Hastings Council, Port Stephens Council, Queanbeyan-Palerang Regional Council, RecycleSmart, Redland City Council (QLD), Shellharbour City Council, Singleton Council, Snowy Valleys Council, South Burnett Regional Council, Stonnington City Council, The Hawkesbury City Council, Sydney, The Hills Shire Council, Sydney, Town of Victoria Park, Townsville, Unley City Council (SA), Wellington Shire Council, Whittlesea City Council, Wollondilly Shire Council, Wollongong City Council, Wyndham City Council, Melbourne, Yarra Ranges Council |
| Australia | Armadale (Western Australia), Australian Capital Territory (ACT), Banyule City Council, Baw Baw Shire Council, Bayside City Council, Bega Valley Shire Council, Belmont City Council, Blacktown City Council (NSW), Blue Mountains City Council, Brisbane City Council, Burwood City Council, Campbelltown City Council (NSW), Cardinia Shire Council, City of Ballarat, City of Canada Bay Council, City of Cockburn, City of Darebin, City of Greater Geelong, City of Kingston, City of Onkaparinga Council, Cowra Council, Cumberland Council (NSW), Forbes Shire Council, Frankston City Council, Gold Coast City Council, Gwydir Shire Council, Hobsons Bay City Council, Hornsby Shire Council, Hume City Council, Impact Apps, Inner West Council (NSW), Ipswich City Council, Knox City Council, Ku-ring-gai Council, Lake Macquarie City Council, Lithgow City Council, Livingstone Shire Council, Loddon Shire Council, Logan City Council, Macedon Ranges Shire Council, Mansfield Shire Council, Maribyrnong Council, Maroondah City Council, Melton City Council, Merri-bek City Council, Moira Shire Council, Moree Plains Shire Council, Moreton Bay, Mosman Council, Nillumbik Shire Council, North Adelaide Waste Management Authority, Penrith City Council, Port Adelaide Enfield, South Australia, Port Macquarie Hastings Council, Port Stephens Council, Queanbeyan-Palerang Regional Council, RecycleSmart, Redland City Council (QLD), Shellharbour City Council, Singleton Council, Snowy Valleys Council, South Burnett Regional Council, Stirling, Stonnington City Council, The Hawkesbury City Council, Sydney, The Hills Shire Council, Sydney, Town of Victoria Park, Townsville, Unley City Council (SA), Wellington Shire Council, Whittlesea City Council, Wollondilly Shire Council, Wollongong City Council, Wyndham City Council, Melbourne, Yarra Ranges Council |
| Austria | Abfallverband Hollabrunn, Abfallverband Korneuburg, Abfallverband Schwechat, Abfallwirtschaft der Stadt St. Pölten, Abfallwirtschaft Stadt Krems, Abfallwirtschaft Stadt St Pölten, Afritz am See, Alpbach, Altenmarkt an der Triesting, Althofen, Andau, Angath, Apetlon, App CITIES, Arnoldstein, Aschau im Zillertal, AWV Neunkirchen, AWV Wr. Neustadt, Bad Blumau, Bad Gleichenberg, Bad Häring, Bad Kleinkirchheim, Bad Loipersdorf, Bad Radkersburg, Bad Tatzmannsdorf, Bad Waltersdorf, Baldramsdorf, Berg im Drautal, Berndorf bei Salzburg, Bernstein, Bildein, Brandenberg, Breitenbach am Inn, Breitenbrunn am Neusiedler See, Breitenstein, Bromberg, Bruckneudorf, Buch - St. Magdalena, Burgau, Burgauberg-Neudauberg, Burgenländischer Müllverband, Dechantskirchen, Dellach, Dellach im Drautal, Deutsch Goritz, Deutsch Jahrndorf, Deutsch Kaltenbrunn, Deutschkreutz, Die NÖ Umweltverbände, Dobl-Zwaring, Drasenhofen, Draßmarkt, Ebenthal in Kärnten, Eberau, Eberndorf, Ebersdorf, Eberstein, Edelsbach bei Feldbach, Eggenburg, Eggersdorf bei Graz, Eichgraben, Eisenstadt, Eugendorf, Fehring, Feistritz im Rosental, Feistritz ob Bleiburg, Feldbach, Feldkirchen in Kärnten, Feldkirchen in Kärnten, Ferlach, Ferndorf, Ferndorf, Finkenstein am Faaker See, Frankenau-Unterpullendorf, Frauenkirchen, Frauenstein, Freistadt, Fresach, Friedberg, Frohnleiten, Fürstenfeld, Gabersdorf, GABL, Gattendorf, GAUL Laa an der Thaya, GAUM Mistelbach, GDA Amstetten, Gemeindeverband Horn, Gitschtal, Gitschtal, Globasnitz, Gmünd in Kärnten, Gols, Grafendorf bei Hartberg, Grafenschachen, Grafenstein, Grafenstein, Gratkorn, Gratwein-Straßengel, Greifenburg, Großkirchheim, Großsteinbach, Großwarasdorf, Großwilfersdorf, Gutenberg, Guttaring, GV Gmünd, GV Krems, GV Zwettl, GVA Baden, GVA Baden, GVA Lilienfeld, GVA Mödling, GVA Tulln, GVA Waidhofen/Thaya, GVU Bezirk Gänserndorf, GVU Melk, GVU Scheibbs, GVU Scheibbs, GVU St. Pölten, Güssing, Hagenberg im Mühlkreis, Hannersdorf, Hartberg, Heiligenblut am Großglockner, Heiligenkreuz, Heiligenkreuz am Waasen, Heimschuh, Henndorf am Wallersee, Henndorf am Wallersee, Hermagor-Pressegger See, Hirm, Hofstätten an der Raab, Hopfgarten im Brixental, Horitschon, Horn, Hornstein, Hüttenberg, Ilz, infeo, Innsbrucker Kommunalbetriebe, Inzenhof, Irschen, Jabing, Jagerberg, Kaindorf, Kaisersdorf, Kalsdorf bei Graz, Kapfenstein, Kemeten, Keutschach am See, Kirchbach, Kirchbach-Zerlach, Kirchberg an der Raab, Kirchbichl, Kirchdorf in Tirol, Kittsee, Klagenfurt am Wörthersee, Kleblach-Lind, Kleinmürbisch, Klingenbach, Klosterneuburg, Klöch, Kobersdorf, Kohfidisch, Korneuburg, Krems in Kärnten, Krensdorf, Krumpendorf am Wörthersee, Kuchl, Kundl, Kössen, Köstendorf, Kötschach-Mauthen, Köttmannsdorf, Laa an der Thaya, Lackenbach, Lackendorf, Langau, Langenrohr, Leibnitz, Leithaprodersdorf, Lendorf, Leoben, Lesachtal, Leutschach an der Weinstraße, Lieboch, Linz AG, Litzelsdorf, Lockenhaus, Loipersbach im Burgenland, Ludmannsdorf, Lurnfeld, Magdalensberg, Mallnitz, Malta, Maria Rain, Maria Saal, Maria Wörth, Mariasdorf, Markt Hartmannsdorf, Markt Neuhodis, Marktgemeinde Edlitz, Marz, Mattersburg, Mattsee, Meiseldorf, Melk, Mettersdorf am Saßbach, Miesenbach, Millstatt, Mischendorf, Mistelbach, Mitterdorf an der Raab, Moosburg, Mureck, Mönchhof, Mörbisch am See, Mörtschach, Mühldorf, Müll App, Münster, Neudorf bei Parndorf, Neudörfl, Neufeld an der Leitha, Neumarkt am Wallersee, Neusiedl am See, Neustift bei Güssing, Nickelsdorf, Oberdrauburg, Oberndorf in Tirol, Oberpullendorf, Oberschützen, Obertrum am See, Oberwart, Oslip, Ottendorf an der Rittschein, Ottobrunn, Paldau, Pama, Pamhagen, Parndorf, Paternion, Payerbach, Peggau, Pernegg an der Mur, Pernegg im Waldviertel, Pfarrwerfen, Pilgersdorf, Pinggau, Pinkafeld, Podersdorf am See, Poggersdorf, Poggersdorf, Potzneusiedl, Poysdorf, Pöchlarn, Pörtschach am Wörther See, Raach am Hochgebirge, Raasdorf, Radenthein, Radfeld, Radmer, Ragnitz, Raiding, Ramsau im Zillertal, Rangersdorf, Reichenau, Reichenfels, Reith im Alpbachtal, Reißeck, Rennweg am Katschberg, Rohr bei Hartberg, Rohr im Burgenland, Rudersdorf, Rust, Saalfelden am Steinernen Meer, Sachsenburg, Sankt Georgen an der Stiefing, Sankt Gilgen, Sankt Oswald bei Plankenwarth, Schiefling am Wörthersee, Schleedorf, Schrattenberg, Schwadorf, Schwaz, Schwoich, Schäffern, Schützen am Gebirge, Seeboden, Seeham, Seekirchen am Wallersee, Seiersberg-Pirka, Siegendorf, Sigleß, Sigmundsherberg, Sinabelkirchen, Spittal an der Drau, St. Andrä, St. Andrä, St. Andrä am Zicksee, St. Anna am Aigen, St. Egyden am Steinfeld, St. Georgen an der Leys, St. Jakob im Rosental, St. Jakob im Rosental, St. Johann in der Haide, St. Johann in Tirol, St. Konrad, St. Lorenzen am Wechsel, St. Margareten im Rosental, St. Margarethen an der Raab, St. Margarethen im Burgenland, St. Peter - Freienstein, St. Peter am Ottersbach, St. Ruprecht an der Raab, St. Symvaro, St. Veit in der Südsteiermark, Stadt Salzburg, Stadtgemeinde Traiskirchen, Stadtservice Korneuburg, Stall, Stegersbach, Steinbrunn, Steinfeld, Steuerberg, Stinatz, Stiwoll, Stockenboi, Stockerau, Strass im Zillertal, Straß in Steiermark, Straßwalchen, Söchau, Söll, Tadten, Tattendorf, Techelsberg am Wörther See, Thal, Tieschen, Tobaj, Trebesing, Treffen am Ossiacher See, Tulln an der Donau, Umweltprofis, Umweltv, Unterfrauenhaid, Unterkohlstätten, Unterlamm, Unterwart, Vasoldsberg, Velden am Wörther See, Villach, Vordernberg, Völkermarkt, Völkermarkt, Walpersbach, Wattens, Weiden am See, Weitersfeld, Weiz, Weißensee, Weppersdorf, Werfenweng, Wies, Wiesen, Wiesfleck, Wiesmath, Wimpassing an der Leitha, Winden am See, Winklern, Wolfau, Wolfsberg, Wolfsberg, Wolkersdorf im Weinviertel, WSZ Moosburg, Wulkaprodersdorf, Wörterberg, Zagersdorf, Zelking-Matzleinsdorf, Zell, Zell am Ziller, Zellberg, Zillingtal, Zurndorf, Übelbach |
| Belgium | Hygea, Limburg.net, Recycle! |
| Canada | Aurora (ON), Calgary (AB), Calgary, AB, City of Edmonton, AB, City of Greater Sudbury, ON, City of Nanaimo, City of Peterborough, ON, City of Vancouver, County of Simcoe, ON, Halifax, NS, London (ON), Montreal (QC), Ottawa, Canada, RM of Morris, MB, Strathcona County, ON, Toronto (ON), Vaughan (ON), Waste Wise APPS, Winnipeg (MB) |
Expand Down
Loading