From 824f9b9c3c56d6ad7c56b95ef5b048f776adb0cd Mon Sep 17 00:00:00 2001 From: Kieran Murphy Date: Sat, 4 Feb 2023 17:12:52 +1100 Subject: [PATCH 1/2] Added support for Wollongong, Australia --- .../source/wollongongwaste_com_au.py | 79 +++++++++++++++++++ doc/source/wollongongwaste_com_au.md | 55 +++++++++++++ 2 files changed, 134 insertions(+) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/wollongongwaste_com_au.py create mode 100644 doc/source/wollongongwaste_com_au.md diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/wollongongwaste_com_au.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/wollongongwaste_com_au.py new file mode 100644 index 00000000..dc271f3a --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/wollongongwaste_com_au.py @@ -0,0 +1,79 @@ +import json +from datetime import datetime, date, timedelta + +import requests +from waste_collection_schedule import Collection + +TITLE = "Wollongong Council" +DESCRIPTION = "Source script for wollongongwaste.com.au" +URL = "https://wollongongwaste.com" +COUNTRY = "au" +TEST_CASES = { + "TestName1": {"propertyID": "21444"} +} + +API_URL = "https://wollongong.waste-info.com.au/api/v1/properties/" + + +def day_of_week(start_date, end_date, day_of_week_index): + day_of_week_dates = [] + while start_date <= end_date: + if start_date.weekday() == day_of_week_index: + day_of_week_dates.append(start_date) + start_date += timedelta(days=1) + return day_of_week_dates + +class Source: + def __init__(self,propertyID): + self._propertyID = propertyID + self._url = API_URL + + def fetch(self): + # Have to specify a start and end, or the API returns nothing. So lets request this year, and next year. + # start=2022-12-31T13:00:00.000Z&end=2024-12-30T13:00:00.000Z + startdate = datetime(date.today().year-1, 12, 31, 13, 0, 0) + enddate = datetime(date.today().year+1, 12, 31, 13, 0, 0) + + data = { + "start": startdate.strftime("%Y-%m-%dT%H:%M:%S.%fZ"), + "end": enddate.strftime("%Y-%m-%dT%H:%M:%S.%fZ") + } + + r = requests.get(f"{self._url}{self._propertyID}.json", data=data) + d = r.json() + + entries = [] + for entry in d: + if entry['event_type'] == "waste": + dow = entry['daysOfWeek'] + for day in dow: + for pickupdate in day_of_week(startdate, enddate, day-1): + entries.append( + Collection( + date=pickupdate.date(), + t="Waste to Landfill (Red)", + icon = "mdi:trash-can" + ) + ) + if entry['event_type'] == "organic": + dow = entry['daysOfWeek'] + for day in dow: + for pickupdate in day_of_week(startdate, enddate, day-1): + print(pickupdate) + entries.append( + Collection( + date=pickupdate.date(), + t="FOGO (Green)", + icon = "mdi:leaf", + ) + ) + if entry['event_type'] == "recycle": + entries.append( + Collection( + date=date(*map(int, entry['start'].split('-'))), + t="Recycling (Yelllow)", + icon="mdi:recycle" + ) + ) + return entries + diff --git a/doc/source/wollongongwaste_com_au.md b/doc/source/wollongongwaste_com_au.md new file mode 100644 index 00000000..9a93beb3 --- /dev/null +++ b/doc/source/wollongongwaste_com_au.md @@ -0,0 +1,55 @@ +# Wollongong City Council + +Support for schedules provided by [Wollongong Waste](https://www.wollongongwaste.com.au/), serving Wollongong Council in the Illawara, New South Wales, Australia + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: wollongongwaste_com_au + args: + propertyID: UNIQUE_PROPERTY_ID +``` + +### Configuration Variables + +### Configuration Variables + +**propertyID**
+*(string) (mandatory)* + +This is required. + + +#### How to find your `propertyID` + +Get your locality. + +https://wollongong.waste-info.com.au/api/v1/localities.json +get the locality ID from the above json. + +Add it as locality= to the Street query + eg: https://wollongong.waste-info.com.au/api/v1/streets.json?locality=19 +Get the street ID from the above json + +Add it as street= to the property query + eg: https://wollongong.waste-info.com.au/api/v1/properties.json?street=663 +get the property ID from the above json. + +This is your propertyID + +This is all you need to directly query your calendar json in future, you can skip all the above steps once you know your property ID + +You could also use [Waste Calendar](https://www.wollongongwaste.com.au/calendar/) with developer tools open on the Network tab, look up your address, and make note of the filename in the last request. It will be in the format .json + eg: https://wollongong.waste-info.com.au/api/v1/properties/21444.json?start=2022-12-31T13:00:00.000Z&end=2023-12-30T13:00:00.000Z + + +## Example using UPRN +```yaml +waste_collection_schedule: + sources: + - name: wollongongwaste_com_au + args: + uprn: 21444 +``` From fea9a0e953bdf881a3b68b82e16d13ddc7c6a4fe Mon Sep 17 00:00:00 2001 From: Kieran Murphy Date: Sat, 4 Feb 2023 17:25:07 +1100 Subject: [PATCH 2/2] Added support for Wollongong, Australia --- README.md | 1 + info.md | 2 +- 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 0c5b5c38..c0b212a9 100644 --- a/README.md +++ b/README.md @@ -42,6 +42,7 @@ Waste collection schedules in the following formats and countries are supported. - [RecycleSmart](/doc/source/recyclesmart_com.md) / recyclesmart.com - [Stonnington City Council](/doc/source/stonnington_vic_gov_au.md) / stonnington.vic.gov.au - [The Hills Shire Council, Sydney](/doc/source/thehills_nsw_gov_au.md) / thehills.nsw.gov.au +- [Wollongong City Council](/doc/source/wollongongwaste_com_au.md) / wollongongwaste.com.au - [Wyndham City Council, Melbourne](/doc/source/wyndham_vic_gov_au.md) / wyndham.vic.gov.au diff --git a/info.md b/info.md index 280e541c..9ff88446 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 | Banyule City Council, Belmont City Council, Brisbane City Council, Campbelltown City Council, City of Canada Bay Council, Gold Coast City Council, Inner West Council (NSW), Ipswich City Council, Ku-ring-gai Council, Macedon Ranges Shire Council, Maroondah City Council, Melton City Council, Nillumbik Shire Council, North Adelaide Waste Management Authority, RecycleSmart, Stonnington City Council, The Hills Shire Council, Sydney, Wyndham City Council, Melbourne | +| Australia | Banyule City Council, Belmont City Council, Brisbane City Council, Campbelltown City Council, City of Canada Bay Council, Gold Coast City Council, Inner West Council (NSW), Ipswich City Council, Ku-ring-gai Council, Macedon Ranges Shire Council, Maroondah City Council, Melton City Council, Nillumbik Shire Council, North Adelaide Waste Management Authority, RecycleSmart, Stonnington City Council, The Hills Shire Council, Sydney, Wyndham City Council, Melbourne, Wollongong City Council | | Austria | Burgenländischer Müllverband, infeo, Stadtservice Korneuburg, Umweltprofis, WSZ Moosburg | | Belgium | Hygea, Recycle! | | Canada | City of Toronto |