From ed86261cf938a2497b329d3b045b01a3be8a0650 Mon Sep 17 00:00:00 2001 From: "Nathan S. Watson-Haigh" Date: Thu, 23 Feb 2023 01:20:05 +1030 Subject: [PATCH] Add City of Onkaparinga Council --- README.md | 1 + .../source/onkaparingacity_com.py | 80 +++++++++++++++++++ doc/source/onkaparingacity_com.md | 35 ++++++++ info.md | 2 +- 4 files changed, 117 insertions(+), 1 deletion(-) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/onkaparingacity_com.py create mode 100644 doc/source/onkaparingacity_com.md diff --git a/README.md b/README.md index 6faaa5a7..9410cb52 100644 --- a/README.md +++ b/README.md @@ -41,6 +41,7 @@ Waste collection schedules in the following formats and countries are supported. - [Melton City Council](/doc/source/melton_vic_gov_au.md) / melton.vic.gov.au - [Nillumbik Shire Council](/doc/source/nillumbik_vic_gov_au.md) / nillumbik.vic.gov.au - [North Adelaide Waste Management Authority](/doc/source/nawma_sa_gov_au.md) / nawma.sa.gov.au +- [City of Onkaparinga Council](/doc/source/onkaparingacity_com.md) / onkaparingacity.com - [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 diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/onkaparingacity_com.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/onkaparingacity_com.py new file mode 100644 index 00000000..84b6a3b8 --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/onkaparingacity_com.py @@ -0,0 +1,80 @@ +from datetime import datetime +from waste_collection_schedule import Collection # type: ignore[attr-defined] +import json +import requests +from bs4 import BeautifulSoup + +TITLE = "City of Onkaparinga Council" +DESCRIPTION = "Source for City of Onkaparinga Council, Australia." +URL = "https://www.onkaparingacity.com/" +COUNTRY = "au" +TEST_CASES = { + "TestcaseI": {"address": "18 Flagstaff Road, FLAGSTAFF HILL 5159"}, +} + +ICON_MAP = { + "General Waste": "mdi:trash-can", + "Recycling Waste": "mdi:recycle", + "Green Waste": "mdi:leaf", +} + +class Source: + def __init__(self, address): + self._address = address + + def fetch(self): + url = "https://www.onkaparingacity.com/api/v1/myarea/search" + + headers = { + 'referer': 'https://www.onkaparingacity.com/Services/Waste-and-recycling/Bin-collections' + } + + params = { + 'keywords': self._address + } + + r = requests.get(url, params=params, headers=headers) + + addresses = r.json() + + if addresses == 0: + return [] + + url = 'https://www.onkaparingacity.com/ocapi/Public/myarea/wasteservices' + + params = { + 'geolocationid': addresses['Items'][0]['Id'], + 'ocsvclang': 'en-AU' + + } + + r = requests.get(url, params=params, headers=headers) + + waste = r.json() + + soup = BeautifulSoup(waste['responseContent'], "html.parser") + + waste_type = [] + + for tag in soup.find_all("h3"): + if tag.text.startswith('Calendar'): + continue + waste_type.append(tag.text) + + waste_date = [] + for tag in soup.find_all("div", {"class":"next-service"}): + tag_text = tag.text.strip() + if tag_text != "": + date_object = datetime.strptime(tag_text, '%a %d/%m/%Y').date() + waste_date.append(date_object) + + waste = list(zip(waste_type, waste_date)) + + entries = [] + for item in waste: + icon = ICON_MAP.get(item[0]) + entries.append( + Collection(item[1], item[0], icon=icon) + ) + + return entries diff --git a/doc/source/onkaparingacity_com.md b/doc/source/onkaparingacity_com.md new file mode 100644 index 00000000..0b5571b1 --- /dev/null +++ b/doc/source/onkaparingacity_com.md @@ -0,0 +1,35 @@ +# City of Onkaparinga Council + +Support for schedules provided by [City of Onkaparinga Council Waste and Recycling](https://www.onkaparingacity.com/Services/Waste-and-recycling/Bin-collections). + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: onkaparingacity_com + args: + address: ADDRESS +``` + +### Configuration Variables + +**address** +*(string) (required)* + + +## Example + +```yaml +waste_collection_schedule: + sources: + - name: onkaparingacity_com + args: + address: 18 Flagstaff Road, FLAGSTAFF HILL 5159 +``` + +## How to get the source arguments + +Visit the [City of Onkaparinga Council Waste and Recycling](https://www.onkaparingacity.com/Services/Waste-and-recycling/Bin-collections) page and search for your address. +The argument address should match the first result in the search list. +Only the first match will be collected. diff --git a/info.md b/info.md index b434b7e0..c5f96b49 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, Lake Macquarie City Council, Macedon Ranges Shire Council, Maribyrnong Council, Maroondah City Council, Melton City Council, Nillumbik Shire Council, North Adelaide Waste Management Authority, RecycleSmart, Stonnington City Council, The Hills Shire Council, Sydney, Wollongong City Council, 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, Lake Macquarie City Council, Macedon Ranges Shire Council, Maribyrnong Council, Maroondah City Council, Melton City Council, Nillumbik Shire Council, North Adelaide Waste Management Authority, City of Onkaparinga Council, RecycleSmart, Stonnington City Council, The Hills Shire Council, Sydney, Wollongong City Council, Wyndham City Council, Melbourne | | Austria | Burgenländischer Müllverband, infeo, Stadtservice Korneuburg, Umweltprofis, WSZ Moosburg | | Belgium | Hygea, Recycle! | | Canada | City of Toronto |