From f2cd962ecaf50bc55dde22493fa6998b2a55b774 Mon Sep 17 00:00:00 2001 From: Joshua Morgan Date: Sun, 30 Jun 2024 01:44:37 +1000 Subject: [PATCH] Add source: darebin_vic_gov_au (#2199) * Add source: darebin_vic_gov_au * add test case + fix _get_next_n_dates delta being optional + reformatting --------- Co-authored-by: 5ila5 <5ila5@users.noreply.github.com> --- README.md | 1 + .../source/darebin_vic_gov_au.py | 115 ++++++++++++++++++ doc/source/darebin_vic_gov_au.md | 33 +++++ info.md | 2 +- 4 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/darebin_vic_gov_au.py create mode 100644 doc/source/darebin_vic_gov_au.md diff --git a/README.md b/README.md index 5d2bdf00..d436e956 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ Waste collection schedules in the following formats and countries are supported. - [Cardinia Shire Council](/doc/source/cardinia_vic_gov_au.md) / cardinia.vic.gov.au - [City of Ballarat](/doc/source/ballarat_vic_gov_au.md) / ballarat.vic.gov.au - [City of Canada Bay Council](/doc/source/canadabay_nsw_gov_au.md) / canadabay.nsw.gov.au +- [City of Darebin](/doc/source/darebin_vic_gov_au.md) / darebin.vic.gov.au - [City of Greater Geelong](/doc/source/geelongaustralia_com_au.md) / geelongaustralia.com.au - [City of Kingston](/doc/source/kingston_vic_gov_au.md) / kingston.vic.gov.au - [City of Onkaparinga Council](/doc/source/onkaparingacity_com.md) / onkaparingacity.com diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/darebin_vic_gov_au.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/darebin_vic_gov_au.py new file mode 100644 index 00000000..93fdbf4e --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/darebin_vic_gov_au.py @@ -0,0 +1,115 @@ +from datetime import date, timedelta + +import requests +from waste_collection_schedule import Collection # type: ignore[attr-defined] + +TITLE = "City of Darebin" +DESCRIPTION = "Source for City of Darebin waste collection." +URL = "https://www.darebin.vic.gov.au/" +TEST_CASES = { + "274 Gower Street PRESTON 3072": { + "property_location": "274 Gower Street PRESTON 3072" + }, +} + +API_URL = "https://services-ap1.arcgis.com/1WJBRkF3v1EEG5gz/arcgis/rest/services/Waste_Collection_Date/FeatureServer/0/query" +WEEKDAY_MAP = { + "Monday": 0, + "Tuesday": 1, + "Wednesday": 2, + "Thursday": 3, + "Friday": 4, + "Saturday": 5, + "Sunday": 6, +} + + +def _get_next_n_dates(date_obj: date, n: int, delta: timedelta): + next_dates = [] + for _ in range(n): + date_obj += delta + while date_obj <= date.today(): + date_obj += delta + next_dates.append(date_obj) + return next_dates + + +def _get_previous_date_for_day_of_week(day_of_week: int): + today = date.today() + return today - timedelta((today.weekday() - day_of_week + 7) % 7) + + +class Source: + def __init__(self, property_location: str): + self.property_location = property_location + + def fetch(self) -> list[Collection]: + params = { + "where": f"EZI_ADDRESS LIKE '{self.property_location}%'", + "outFields": "EZI_ADDRESS,OBJECTID", + "f": "json", + } + r = requests.get(API_URL, params=params) + r.raise_for_status() + + data = r.json() + features = data.get("features") + attributes = features[0]["attributes"] + object_id = attributes["OBJECTID"] + + params = { + "f": "json", + "objectIds": object_id, + "outFields": "Collection_Day,Condition,EZI_ADDRESS,Green_Collection,Hard_Rubbish_Week_Start,Recycle_Collection", + } + + r = requests.get(API_URL, params=params) + r.raise_for_status() + + data = r.json() + features = data.get("features") + attributes = features[0]["attributes"] + + green_collection_epoch_seconds = attributes["Green_Collection"] / 1000 + recycle_collection_epoch_seconds = attributes["Recycle_Collection"] / 1000 + collection_day = attributes["Collection_Day"] + + next_collection_date = _get_previous_date_for_day_of_week( + WEEKDAY_MAP[collection_day] + ) + + green_collection = date.fromtimestamp(green_collection_epoch_seconds) + recycle_collection = date.fromtimestamp(recycle_collection_epoch_seconds) + + green_collection_dates = _get_next_n_dates( + green_collection, 52, timedelta(days=14) + ) + recycle_collection_dates = _get_next_n_dates( + recycle_collection, 52, timedelta(days=14) + ) + waste_collection_dates = _get_next_n_dates( + next_collection_date, 52, timedelta(days=7) + ) + + entries = [] + + entries.extend( + [ + Collection(date=collection_date, t="Green Waste", icon="mdi:leaf") + for collection_date in green_collection_dates + ] + ) + entries.extend( + [ + Collection(date=collection_date, t="Recycling", icon="mdi:recycle") + for collection_date in recycle_collection_dates + ] + ) + entries.extend( + [ + Collection(date=collection_day, t="Rubbish", icon="mdi:trash-can") + for collection_day in waste_collection_dates + ] + ) + + return entries diff --git a/doc/source/darebin_vic_gov_au.md b/doc/source/darebin_vic_gov_au.md new file mode 100644 index 00000000..973c207b --- /dev/null +++ b/doc/source/darebin_vic_gov_au.md @@ -0,0 +1,33 @@ +# City of Darebin + +Support for schedules provided by [City of Darebin](https://www.darebin.vic.gov.au/Waste-environment-and-climate/Bins-and-waste-collection/When-is-my-bin-collection-day). + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: darebin_vic_gov_au + args: + property_location: PROPERTY_LOCATION + +``` + +### Configuration Variables + +**property_location** +*(string) (required)* + +## Example + +```yaml +waste_collection_schedule: + sources: + - name: darebin_vic_gov_au + args: + property_location: 274 Gower Street PRESTON 3072 +``` + +## How to get the source arguments + +Visit the [City of Darebin Find my bin collection day page](https://darebin.maps.arcgis.com/apps/instant/basic/index.html?appid=51d4de7339f84dd5a6d2790cb2081be2) page and search for your address. The argument should exactly match the result shown for Address portion of the Property Information. diff --git a/info.md b/info.md index fa4f89a8..f9243a6d 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), Frankston City Council, Gold Coast City Council, Hobsons Bay City Council, Hornsby Shire Council, Hume City Council, Inner West Council (NSW), Ipswich City Council, Knox 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, Merri-bek City Council, Moreton Bay, Mosman Council, Nillumbik Shire Council, North Adelaide Waste Management Authority, Port Adelaide Enfield, South Australia, Port Stephens Council, RecycleSmart, Redland City Council (QLD), Shellharbour City Council, Stonnington City Council, The Hawkesbury City Council, Sydney, The Hills Shire Council, Sydney, Town of Victoria Park, Townsville, Unley City Council (SA), 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, 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 Darebin, City of Greater Geelong, City of Kingston, City of Onkaparinga Council, Cumberland Council (NSW), Frankston City Council, Gold Coast City Council, Hobsons Bay City Council, Hornsby Shire Council, Hume City Council, Inner West Council (NSW), Ipswich City Council, Knox 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, Merri-bek City Council, Moreton Bay, Mosman Council, Nillumbik Shire Council, North Adelaide Waste Management Authority, Port Adelaide Enfield, South Australia, Port Stephens Council, RecycleSmart, Redland City Council (QLD), Shellharbour City Council, Stonnington City Council, The Hawkesbury City Council, Sydney, The Hills Shire Council, Sydney, Town of Victoria Park, Townsville, Unley City Council (SA), 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, London (ON), Montreal (QC), Ottawa, Canada, RM of Morris, MB, Strathcona County, ON, Toronto (ON), Vaughan (ON), Waste Wise APPS, Winnipeg (MB) |