From 14cd06c2e123cc52c2cddf4e8bfd8232563e945a Mon Sep 17 00:00:00 2001 From: dt215git <86194065+dt215git@users.noreply.github.com> Date: Sat, 2 Sep 2023 10:50:55 +0100 Subject: [PATCH] New Source: Allerdale, UK (#1222) * allerdale adapted from eastherts * allerdale .md added * update_docu_links run * fix typo --- README.md | 1 + .../source/allerdale_gov_uk.py | 112 ++++++++++++++++++ doc/source/allerdale_gov_uk.md | 36 ++++++ info.md | 2 +- 4 files changed, 150 insertions(+), 1 deletion(-) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/allerdale_gov_uk.py create mode 100644 doc/source/allerdale_gov_uk.md diff --git a/README.md b/README.md index 081a81d1a..0c38f88c2 100644 --- a/README.md +++ b/README.md @@ -734,6 +734,7 @@ Waste collection schedules in the following formats and countries are supported. United Kingdom - [Aberdeenshire Council](/doc/source/aberdeenshire_gov_uk.md) / aberdeenshire.gov.uk +- [Allerdale Borough Council](/doc/source/allerdale_gov_uk.md) / allerdale.gov.uk - [Amber Valley Borough Council](/doc/source/ambervalley_gov_uk.md) / ambervalley.gov.uk - [Ashfield District Council](/doc/source/ashfield_gov_uk.md) / ashfield.gov.uk - [Ashford Borough Council](/doc/source/ashford_gov_uk.md) / ashford.gov.uk diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/allerdale_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/allerdale_gov_uk.py new file mode 100644 index 000000000..429939ff1 --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/allerdale_gov_uk.py @@ -0,0 +1,112 @@ +import logging +from datetime import datetime + +import requests +from bs4 import BeautifulSoup +from waste_collection_schedule import Collection # type: ignore[attr-defined] + +TITLE = "Allerdale Borough Council" +DESCRIPTION = "Source for www.allerdale.gov.uk services for Allerdale Borough Council." +URL = "https://www.allerdale.gov.uk" +TEST_CASES = { + "Keswick": { + "address_postcode": "CA12 4HU", + "address_name_number": "11", + }, + "Workington": { + "address_postcode": "CA14 3NS", + "address_name_number": "177", + }, + "Wigton": { + "address_postcode": "CA7 9RS", + "address_name_number": "55", + }, +} +ICON_MAP = { + "Domestic Waste": "mdi:trash-can", + "Glass Cans and Plastic Recycling": "mdi:recycle", + "Garden Waste": "mdi:leaf", +} +API_URL = "https://abc-wrp.whitespacews.com/" + +_LOGGER = logging.getLogger(__name__) + + +class Source: + def __init__( + self, + address_name_number=None, + address_postcode=None, + ): + self._address_name_number = address_name_number + self._address_postcode = address_postcode + + def fetch(self): + session = requests.Session() + + # get link from first page as has some kind of unique hash + r = session.get( + API_URL, + ) + r.raise_for_status() + soup = BeautifulSoup(r.text, features="html.parser") + + alink = soup.find("a", text="View My Collections") + + if alink is None: + raise Exception("Initial page did not load correctly") + + # replace 'seq' query string to skip next step + nextpageurl = alink["href"].replace("seq=1", "seq=2") + + data = { + "address_name_number": self._address_name_number, + "address_postcode": self._address_postcode, + } + + # get list of addresses + r = session.post(nextpageurl, data) + r.raise_for_status() + + soup = BeautifulSoup(r.text, features="html.parser") + + # get first address (if you don't enter enough argument values this won't find the right address) + alink = soup.find("div", id="property_list").find("a") + + if alink is None: + raise Exception("Address not found") + + nextpageurl = API_URL + alink["href"] + + # get collection page + r = session.get( + nextpageurl, + ) + r.raise_for_status() + soup = BeautifulSoup(r.text, features="html.parser") + + if soup.find("span", id="waste-hint"): + raise Exception("No scheduled services at this address") + + u1s = soup.find("section", id="scheduled-collections").find_all("u1") + + entries = [] + + for u1 in u1s: + lis = u1.find_all("li", recursive=False) + entries.append( + Collection( + date=datetime.strptime( + lis[1].text.replace("\n", ""), "%d/%m/%Y" + ).date(), + t=lis[2].text.replace("\n", ""), + icon=ICON_MAP.get( + lis[2] + .text.replace("\n", "") + .replace(" Collection", "") + .replace(" Service", "") + ), + ) + ) + + return entries diff --git a/doc/source/allerdale_gov_uk.md b/doc/source/allerdale_gov_uk.md new file mode 100644 index 000000000..4ebd060d4 --- /dev/null +++ b/doc/source/allerdale_gov_uk.md @@ -0,0 +1,36 @@ +# Allerdale Borough Council + +Support for schedules provided by [Allerdale Borough Council](https://www.allerdale.gov.uk/en/waste-recycling/), serving the Allerdale district, UK. + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: allerdale_gov_uk + args: + address_postcode: POST_CODE + address_name_number: HOUSE_NAME_NUMBER +``` + +### Configuration Variables +If you have a house name, or both a house name and house number, determine which is best to use manually at [Allerdale Borough Council](https://www.allerdale.gov.uk/en/waste-recycling/). + + +**ADDRESS_POSTCODE** +*(string) (required)* + +**ADDRESS_NAME_NUMBER** +*(string) (required)* + + +## Example + +```yaml +waste_collection_schedule: + sources: + - name: allerdale_gov_uk + args: + address_postcode: "CA12 4HU" + address_name_number: "11" +``` diff --git a/info.md b/info.md index 19ec51e5d..2a4453640 100644 --- a/info.md +++ b/info.md @@ -31,7 +31,7 @@ Waste collection schedules from service provider web sites are updated daily, de | Slovenia | Moji odpadki, Ljubljana | | Sweden | Affärsverken, 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, Uppsala Vatten och Avfall AB, 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, Real Luzern, Rehetobel, Rorschach, Rorschacherberg, Schwellbrunn, Schönengrund, Speicher, Stein, Steinach, Teufen, Thal, Trogen, Tübach, Untereggen, Urnäsch, Wald, Waldkirch, Waldstatt, Wittenbach, Wolfhalden | -| United Kingdom | Aberdeenshire Council, Amber Valley Borough Council, Ashfield District Council, Ashford Borough Council, Aylesbury Vale District Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Borough Council of King's Lynn & West Norfolk, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District Council, Broxtowe Borough Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Burnley Council, Cambridge City Council, Canterbury City Council, Cardiff Council, Central Bedfordshire Council, Cherwell District Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City of York Council, Colchester City Council, Cornwall Council, Crawley Borough Council (myCrawley), Croydon Council, Derby City Council, Dudley Metropolitan Borough Council, Durham County Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, East Renfrewshire Council, East Riding of Yorkshire Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Gateshead Council, Glasgow City Council, Guildford Borough Council, Gwynedd, Harborough District Council, Harlow Council, Herefordshire City Council, Highland, Horsham District Council, Huntingdonshire District Council, iTouchVision, Joint Waste Solutions, Kirklees Council, Leicester City Council, Lewes District Council, Lisburn and Castlereagh City Council, Liverpool City Council, London Borough of Bexley, London Borough of Bromley, London Borough of Camden, London Borough of Lewisham, London Borough of Merton, Maidstone Borough Council, Maldon District Council, Manchester City Council, Mendip District Council, Mid-Sussex District Council, Middlesbrough Council, Milton Keynes council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Somerset Council, North Yorkshire Council - Hambleton, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough Council, Rhondda Cynon Taf County Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushcliffe Brough Council, Rushmoor Borough Council, Salford City Council, Sedgemoor District Council, Sheffield City Council, Somerset Council, Somerset County Council, Somerset West & Taunton District Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Holland District Council, South Norfolk Council, South Oxfordshire District Council, South Somerset District Council, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, Swindon Borough Council, Telford and Wrekin Council, Test Valley Borough Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Warrington Borough Council, Waverley Borough Council, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Windsor and Maidenhead, Wirral Council, Woking Borough Council, Wyre Forest District Council | +| United Kingdom | Aberdeenshire Council, Allerdale Borough Council, Amber Valley Borough Council, Ashfield District Council, Ashford Borough Council, Aylesbury Vale District Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Borough Council of King's Lynn & West Norfolk, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District Council, Broxtowe Borough Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Burnley Council, Cambridge City Council, Canterbury City Council, Cardiff Council, Central Bedfordshire Council, Cherwell District Council, Cheshire East Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City of York Council, Colchester City Council, Cornwall Council, Crawley Borough Council (myCrawley), Croydon Council, Derby City Council, Dudley Metropolitan Borough Council, Durham County Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, East Renfrewshire Council, East Riding of Yorkshire Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Gateshead Council, Glasgow City Council, Guildford Borough Council, Gwynedd, Harborough District Council, Harlow Council, Herefordshire City Council, Highland, Horsham District Council, Huntingdonshire District Council, iTouchVision, Joint Waste Solutions, Kirklees Council, Leicester City Council, Lewes District Council, Lisburn and Castlereagh City Council, Liverpool City Council, London Borough of Bexley, London Borough of Bromley, London Borough of Camden, London Borough of Lewisham, London Borough of Merton, Maidstone Borough Council, Maldon District Council, Manchester City Council, Mendip District Council, Mid-Sussex District Council, Middlesbrough Council, Milton Keynes council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Somerset Council, North Yorkshire Council - Hambleton, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough Council, Rhondda Cynon Taf County Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushcliffe Brough Council, Rushmoor Borough Council, Salford City Council, Sedgemoor District Council, Sheffield City Council, Somerset Council, Somerset County Council, Somerset West & Taunton District Council, South Cambridgeshire District Council, South Derbyshire District Council, South Gloucestershire Council, South Hams District Council, South Holland District Council, South Norfolk Council, South Oxfordshire District Council, South Somerset District Council, South Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, Swindon Borough Council, Telford and Wrekin Council, Test Valley Borough Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Warrington Borough Council, Waverley Borough Council, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Windsor and Maidenhead, Wirral Council, Woking Borough Council, Wyre Forest District Council | | United States of America | Albuquerque, New Mexico, USA, City of Bloomington, City of Cambridge, City of Gastonia, NC, City of Georgetown, TX, City of Oklahoma City, City of Pittsburgh, Louisville, Kentucky, USA, Newark, Delaware, USA, Olympia, Washington, USA, ReCollect, Recycle Coach, Republic Services, Seattle Public Utilities, Tucson, Arizona, USA |