diff --git a/.gitignore b/.gitignore index 82f21bbc..c9d57830 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,4 @@ custom_components/waste_collection_schedule/waste_collection_schedule/test/secre .DS_Store .venv/ .idea/ +.python-version \ No newline at end of file diff --git a/README.md b/README.md index 2bc81fde..acf0ce02 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/hobsonsbay_vic_gov_au.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/hobsonsbay_vic_gov_au.py new file mode 100644 index 00000000..58af6ab0 --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/hobsonsbay_vic_gov_au.py @@ -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": "", + "highlightPreTag": "", + "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 diff --git a/doc/source/hobsonsbay_vic_gov_au.md b/doc/source/hobsonsbay_vic_gov_au.md new file mode 100644 index 00000000..d9c154d8 --- /dev/null +++ b/doc/source/hobsonsbay_vic_gov_au.md @@ -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. diff --git a/info.md b/info.md index 887271e2..3b434310 100644 --- a/info.md +++ b/info.md @@ -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 | -| Australia | Armadale (Western Australia), Australian Capital Territory (ACT), Banyule City Council, Belmont City Council, Blacktown City Council (NSW), Brisbane City Council, Campbelltown City Council (NSW), Cardinia Shire Council, City of Ballarat, City of Canada Bay Council, City of Greater Geelong, City of Kingston, City of Onkaparinga Council, Cumberland Council (NSW), Gold Coast City Council, Hume City Council, Inner West Council (NSW), Ipswich City Council, Ku-ring-gai Council, Lake Macquarie City Council, Logan City Council, Macedon Ranges Shire Council, Mansfield Shire Council, Maribyrnong Council, Maroondah City Council, Melton City Council, Moreton Bay, Nillumbik Shire Council, North Adelaide Waste Management Authority, Port Adelaide Enfield, South Australia, RecycleSmart, Shellharbour City Council, Stonnington City Council, The Hills Shire Council, Sydney, Unley City Council (SA), Whittlesea City Council, Wollongong City Council, Wyndham City Council, Melbourne, Yarra Ranges Council | +| Australia | Armadale (Western Australia), Australian Capital Territory (ACT), Banyule City Council, Belmont City Council, Blacktown City Council (NSW), Brisbane City Council, Campbelltown City Council (NSW), Cardinia Shire Council, City of Ballarat, City of Canada Bay Council, City of Greater Geelong, City of Kingston, City of Onkaparinga Council, Cumberland Council (NSW), Gold Coast City Council, Hobsons Bay City Council, Hume City Council, Inner West Council (NSW), Ipswich City Council, Ku-ring-gai Council, Lake Macquarie City Council, Logan City Council, Macedon Ranges Shire Council, Mansfield Shire Council, Maribyrnong Council, Maroondah City Council, Melton City Council, Moreton Bay, Nillumbik Shire Council, North Adelaide Waste Management Authority, Port Adelaide Enfield, South Australia, RecycleSmart, Shellharbour City Council, Stonnington City Council, The Hills Shire Council, Sydney, Unley City Council (SA), Whittlesea City Council, Wollongong City Council, Wyndham City Council, Melbourne, Yarra Ranges Council | | Austria | Abfallverband Hollabrunn, Abfallverband Korneuburg, Abfallverband Schwechat, 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, 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, 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 Peterborough, ON, City of Vancouver, London (ON), Ottawa, Canada, RM of Morris, MB, Strathcona County, ON, Toronto (ON), Vaughan (ON), Waste Wise APPS |