diff --git a/README.md b/README.md index ef07aafe..a9fff0da 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ Waste collection schedules in the following formats and countries are supported. - [Campbelltown City Council (NSW)](/doc/source/campbelltown_nsw_gov_au.md) / campbelltown.nsw.gov.au - [Cardinia Shire Council](/doc/source/cardinia_vic_gov_au.md) / cardinia.vic.gov.au - [City of Canada Bay Council](/doc/source/canadabay_nsw_gov_au.md) / canadabay.nsw.gov.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 - [Gold Coast City Council](/doc/source/goldcoast_qld_gov_au.md) / goldcoast.qld.gov.au - [Hume City Council](/doc/source/hume_vic_gov_au.md) / hume.vic.gov.au diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/kingston_vic_gov_au.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/kingston_vic_gov_au.py new file mode 100644 index 00000000..58f4eb87 --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/kingston_vic_gov_au.py @@ -0,0 +1,105 @@ +import datetime +import json +import requests + +from bs4 import BeautifulSoup +from requests.utils import requote_uri +from waste_collection_schedule import Collection + +TITLE = "City of Kingston" +DESCRIPTION = "Source for City of Kingston (VIC) waste collection." +URL = "https://www.kingston.vic.gov.au" +TEST_CASES = { + "randomHouse": { + "post_code": "3169", + "suburb": "CLAYTON SOUTH", + "street_name": "Oakes Avenue", + "street_number": "30C", + }, + "randomAppartment": { + "post_code": "3197", + "suburb": "CARRUM", + "street_name": "Whatley Street", + "street_number": "1/51", + }, + "randomMultiunit": { + "post_code": "3189", + "suburb": "MOORABBIN", + "street_name": "Station Street", + "street_number": "1/1-5", + }, + "stringCheck": { + "post_code": 3195, + "suburb": "mordialloc", + "street_name": "albert street", + "street_number": 117, + }, +} +API_URLS = { + "session":"https://www.kingston.vic.gov.au", + "search": "https://www.kingston.vic.gov.au/api/v1/myarea/search?keywords={}", + "schedule": "https://www.kingston.vic.gov.au/ocapi/Public/myarea/wasteservices?geolocationid={}&ocsvclang=en-AU", +} +HEADERS = { + "user-agent": "Mozilla/5.0", +} +ICON_MAP = { + "General waste (landfill)": "mdi:trash-can", + "Recycling": "mdi:recycle", + "Food and garden waste": "mdi:leaf", +} + +# _LOGGER = logging.getLogger(__name__) + + +class Source: + def __init__( + self, post_code: str, suburb: str, street_name: str, street_number: str + ): + self.post_code = str(post_code).upper() + self.suburb = suburb.upper() + self.street_name = street_name.upper() + self.street_number = str(street_number).upper() + + def fetch(self): + + # 'collection' api call seems to require an ASP.Net_sessionID, so obtain the relevant cookie + s = requests.Session() + q = requote_uri(str(API_URLS["session"])) + r0 = s.get(q, headers = HEADERS) + + # Do initial address search + address = "{} {} {} {}".format(self.street_number, self.street_name, self.suburb, self.post_code) + q = requote_uri(str(API_URLS["search"]).format(address)) + r1 = s.get(q, headers = HEADERS) + data = json.loads(r1.text)["Items"] + + # Find the geolocation for the address + locationId = "" + for item in data: + if address in item['AddressSingleLine']: + locationId = item["Id"] + + # Retrieve the upcoming collections for location + q = requote_uri(str(API_URLS["schedule"]).format(locationId)) + r2 = s.get(q, headers = HEADERS) + data = json.loads(r2.text) + responseContent = data["responseContent"] + + soup = BeautifulSoup(responseContent, "html.parser") + services = soup.find_all("article") + + entries = [] + + for item in services: + waste_type = item.find('h3').text + date = datetime.datetime.strptime(item.find('div', {'class': 'next-service'}).text.strip(), "%a %d/%m/%Y").date() + entries.append( + Collection( + date = date, + t=waste_type, + icon=ICON_MAP.get(waste_type), + ) + ) + + return entries diff --git a/doc/source/kingston_vic_gov_au.md b/doc/source/kingston_vic_gov_au.md new file mode 100644 index 00000000..164185da --- /dev/null +++ b/doc/source/kingston_vic_gov_au.md @@ -0,0 +1,47 @@ +# City of Kingston, VIC + +Support for schedules provided by [City of Kingston Bins and Collections](https://www.kingston.vic.gov.au/services/rubbish-and-recycling/bins-and-collections#bin-day). + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: kingston_vic_gov_au + args: + post_code: POST_CODE + suburb: SUBURB + street_name: STREET_NAME + street_number: STREET_NUMBER +``` + +### Configuration Variables + +**post_code** +*(string) (required)* + +**suburb** +*(string) (required)* + +**street_name** +*(string) (required)* + +**street_number** +*(string) (required)* + +## Example + +```yaml +waste_collection_schedule: + sources: + - name: kington_vic_gov_au + args: + post_code: "3189" + suburb: "MOORABBIN" + street_name: "Station Street" + street_number: "1/1-5" +``` + +## How to get the source arguments + +Visit the [City of Kingston Bins and Collections](https://www.kingston.vic.gov.au/services/rubbish-and-recycling/bins-and-collections#bin-day) page and search for your address. The args should exactly match the how your address is shown when you've selected your address. \ No newline at end of file diff --git a/info.md b/info.md index dc02f6a1..df443b67 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 (NSW), Cardinia Shire Council, City of Canada Bay Council, City of Onkaparinga Council, Gold Coast City Council, Hume 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, Unley City Council (SA), Whittlesea City Council, Wollongong City Council, Wyndham City Council, Melbourne | +| Australia | Banyule City Council, Belmont City Council, Brisbane City Council, Campbelltown City Council (NSW), Cardinia Shire Council, City of Canada Bay Council, City of Kingston, City of Onkaparinga Council, Gold Coast City Council, Hume 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, Unley City Council (SA), Whittlesea City Council, Wollongong City Council, Wyndham City Council, Melbourne | | Austria | Andau, Apetlon, App CITIES, Bad Blumau, Bad Gleichenberg, Bad Loipersdorf, Bad Radkersburg, Bad Tatzmannsdorf, Bildein, Breitenbrunn am Neusiedler See, Breitenstein, Bruckneudorf, Buch - St. Magdalena, Burgau, Burgenländischer Müllverband, Dechantskirchen, Deutsch Goritz, Deutsch Jahrndorf, Deutsch Kaltenbrunn, Deutschkreutz, Dobl-Zwaring, Draßmarkt, Eberau, Eberndorf, Eberstein, Edelsbach bei Feldbach, Eggersdorf bei Graz, Eisenstadt, Fehring, Feistritz ob Bleiburg, Feldbach, Frankenau-Unterpullendorf, Frauenkirchen, Freistadt, Friedberg, Fürstenfeld, Gabersdorf, Gattendorf, Gols, Grafendorf bei Hartberg, Grafenstein, Gratkorn, Großwarasdorf, Großwilfersdorf, Gutenberg-Stenzengreith, Güssing, Hartberg, Heiligenkreuz am Waasen, Hofstätten an der Raab, Horitschon, Hornstein, Hüttenberg, Ilz, infeo, Innsbrucker Kommunalbetriebe, Jabing, Jagerberg, Kaindorf, Kaisersdorf, Kalsdorf bei Graz, Kapfenstein, Kirchberg an der Raab, Kleinmürbisch, Klingenbach, Klöch, Kohfidisch, Korneuburg, Laa an der Thaya, Leithaprodersdorf, Lieboch, Litzelsdorf, Loipersbach im Burgenland, Mariasdorf, Markt Hartmannsdorf, Markt Neuhodis, Marz, Mattersburg, Melk, Mettersdorf am Saßbach, Mischendorf, Mistelbach, Mitterdorf an der Raab, Mureck, Mörbisch am See, Neudorf bei Parndorf, Neufeld an der Leitha, Neusiedl am See, Nickelsdorf, Oberpullendorf, Oberwart, Oslip, Ottendorf an der Rittschein, Paldau, Pamhagen, Parndorf, Peggau, Pernegg an der Mur, Pilgersdorf, Pinggau, Pinkafeld, Podersdorf am See, Poggersdorf, Potzneusiedl, Poysdorf, Pöchlarn, Radmer, Ragnitz, Raiding, Rudersdorf, Rust, Saalfelden am Steinernen Meer, Sankt Oswald bei Plankenwarth, Schäffern, Schützen am Gebirge, Seiersberg-Pirka, Sigleß, Sinabelkirchen, St. Andrä, St. Anna am Aigen, St. Johann in der Haide, St. Lorenzen am Wechsel, St. Margarethen an der Raab, St. Margarethen im Burgenland, St. Peter - Freienstein, St. Peter am Ottersbach, St. Ruprecht an der Raab, St. Veit in der Südsteiermark, Stadt Salzburg, Stadtservice Korneuburg, Stegersbach, Steinbrunn, Steuerberg, Stinatz, Stiwoll, Stockerau, Söchau, Thal, Tieschen, Tulln an der Donau, Umweltprofis, Unterfrauenhaid, Unterkohlstätten, Unterlamm, Vasoldsberg, Vordernberg, Völkermarkt, Weiz, Werfenweng, Wies, Wiesen, Wiesfleck, Wimpassing an der Leitha, Winden am See, Wolfsberg, Wolkersdorf im Weinviertel, WSZ Moosburg, Zagersdorf, Zillingtal, Zurndorf, Übelbach | | Belgium | Hygea, Limburg.net, Recycle! | | Canada | City of Toronto |