From 210500e5e7854f37ffe8cb5625da38043c190e51 Mon Sep 17 00:00:00 2001 From: Josh Willcock Date: Sun, 12 Mar 2023 22:08:58 +0000 Subject: [PATCH] adding swindon_gov_uk --- README.md | 1 + .../source/swindon_gov_uk.py | 54 +++++++++++++++++++ doc/source/swindon_gov_uk.md | 36 +++++++++++++ info.md | 2 +- 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/swindon_gov_uk.py create mode 100644 doc/source/swindon_gov_uk.md diff --git a/README.md b/README.md index d4efc68c..7e148431 100644 --- a/README.md +++ b/README.md @@ -466,6 +466,7 @@ Waste collection schedules in the following formats and countries are supported. - [Southampton City Council](/doc/source/southampton_gov_uk.md) / southampton.gov.uk - [Stevenage Borough Council](/doc/source/stevenage_gov_uk.md) / stevenage.gov.uk - [Stockport Council](/doc/source/stockport_gov_uk.md) / stockport.gov.uk +- [Swindon Borough Council](/doc/source/swindon_gov_uk.md) / swindon.gov.uk - [Telford and Wrekin Council](/doc/source/telford_gov_uk.md) / telford.gov.uk - [Tewkesbury Borough Council](/doc/source/tewkesbury_gov_uk.md) / tewkesbury.gov.uk - [The Royal Borough of Kingston Council](/doc/source/kingston_gov_uk.md) / kingston.gov.uk diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/swindon_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/swindon_gov_uk.py new file mode 100644 index 00000000..ca127f3f --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/swindon_gov_uk.py @@ -0,0 +1,54 @@ +import requests +from bs4 import BeautifulSoup +from dateutil import parser +from waste_collection_schedule import Collection + +TITLE = "Swindon Borough Council" +DESCRIPTION = "Swindon Borough Council, UK - Waste Collection" +URL = "https://www.swindon.gov.uk" +TEST_CASES = { + "1 Nyland Road": {"uprn": "100121147490"}, + "74 Standen Way": {"uprn": "200002922415"}, + "1 Eastbury Way": {"uprn": "10010424600"}, + "33 Ulysses Road": {"uprn": "10010427033"} +} + +ICON_MAP = { + "Rubbish bin": "mdi:trash-can", + "Recycling boxes": "mdi:recycle", + "Garden waste bin": "mdi:leaf", + "Plastics": "mdi:sack", +} + + +class Source: + def __init__(self, uprn: str): + self.uprn = uprn + self.url = f"{URL}/info/20122/rubbish_and_recycling_collection_days?uprnSubmit=Yes&addressList={self.uprn}" + + def fetch(self): + collection_lookup = requests.post( + f"{URL}/info/20122/rubbish_and_recycling_collection_days?uprnSubmit=Yes&addressList={self.uprn}" + ) + collection_lookup.raise_for_status() + + entries = [] + for results in BeautifulSoup(collection_lookup.text, "html.parser").find_all( + "div", class_="bin-collection-content" + ): + + try: + recyclingdate = results.find("span", class_="nextCollectionDate"); + + if recyclingdate != None : + recyclingtype = results.find('div', class_='content-left').find("h3"); + entries.append( + Collection( + date=parser.parse(recyclingdate.text, dayfirst=True).date(), + t=recyclingtype.text, + icon=ICON_MAP.get(recyclingtype.text), + ) + ) + except (StopIteration, TypeError): + pass + return entries \ No newline at end of file diff --git a/doc/source/swindon_gov_uk.md b/doc/source/swindon_gov_uk.md new file mode 100644 index 00000000..02776b8d --- /dev/null +++ b/doc/source/swindon_gov_uk.md @@ -0,0 +1,36 @@ +# Swindon Borough Council + +Support for schedules provided by [Swindon Borough Council](https://swindon.gov.uk/). + +If collection data is available for the address provided, it will return household and recycling waste collection dates. + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: swindon_gov_uk + args: + uprn: UPRN +``` + +### Configuration Variables + +**uprn** +*(string) (required)* + +Only the UPRN should be supplied in the arguments. + +## Examples + +```yaml +waste_collection_schedule: + sources: + - name: swindon_gov_uk + args: + uprn: 100121147490 +``` + +## How to find your UPRN + +An easy way to discover your Unique Property Reference Number (UPRN) is by going to [Find My Address](https://www.findmyaddress.co.uk/) and providng your address details. \ No newline at end of file diff --git a/info.md b/info.md index fd9835ee..81daa885 100644 --- a/info.md +++ b/info.md @@ -29,7 +29,7 @@ Waste collection schedules from service provider web sites are updated daily, de | Slovenia | Moji odpadki, Ljubljana | | Sweden | Jönköping - June Avfall & Miljö, Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Linköping - Tekniska Verken, Region Gotland, Ronneby Miljöteknik, Samverkan Återvinning Miljö (SÅM), SRV Återvinning, SSAM, Sysav Sophämntning, VA Syd Sophämntning | | Switzerland | A-Region, Andwil, Appenzell, Berg, Bühler, Eggersriet, Gais, Gaiserwald, Goldach, Grosswangen, Grub, Heiden, Herisau, Horn, Hundwil, Häggenschwil, Lindau, Lutzenberg, Muolen, Mörschwil, Münchenstein, Rehetobel, Rorschach, Rorschacherberg, Schwellbrunn, Schönengrund, Speicher, Stein, Steinach, Teufen, Thal, Trogen, Tübach, Untereggen, Urnäsch, Wald, Waldkirch, Waldstatt, Wittenbach, Wolfhalden | -| United Kingdom | Amber Valley Borough Council, Ashfield District Council, Basingstoke and Deane Borough Council, Binzone, Blackburn with Darwen Borough Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of York Council, Colchester City Council, Cornwall Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, FCC Environment, Glasgow City Council, Guildford Borough Council, Harborough District Council, Harlow Council, Herefordshire City Council, Horsham District Council, Huntingdonshire District Council, Lewes District Council, Liverpool City Council, London Borough of Lewisham, Maldon District Council, Manchester City Council, Mid-Sussex District Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Somerset Council, Nottingham City Council, Oxford City Council, Peterborough City Council, Richmondshire District Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Derbyshire District Council, South Hams District Council, South Norfolk and Broadland Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Uttlesford District Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough Council, Wiltshire Council, Wyre Forest District Council | +| United Kingdom | Amber Valley Borough Council, Ashfield District Council, Basingstoke and Deane Borough Council, Binzone, Blackburn with Darwen Borough Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Cambridge City Council, Canterbury City Council, Central Bedfordshire Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of York Council, Colchester City Council, Cornwall Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, FCC Environment, Glasgow City Council, Guildford Borough Council, Harborough District Council, Harlow Council, Herefordshire City Council, Horsham District Council, Huntingdonshire District Council, Lewes District Council, Liverpool City Council, London Borough of Lewisham, Maldon District Council, Manchester City Council, Mid-Sussex District Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Somerset Council, Nottingham City Council, Oxford City Council, Peterborough City Council, Richmondshire District Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Derbyshire District Council, South Hams District Council, South Norfolk and Broadland Council, South Oxfordshire District Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Swindon Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough Council, Wiltshire Council, Wyre Forest District Council | | United States of America | City of Pittsburgh, Republic Services, Seattle Public Utilities |