From 2988bb9725b3014c40aac238937a7693439a0b66 Mon Sep 17 00:00:00 2001 From: 5ila5 <5ila5@users.noreply.github.com> Date: Mon, 24 Jun 2024 12:06:02 +0200 Subject: [PATCH] add solihull_gov_uk --- README.md | 1 + .../source/solihull_gov_uk.py | 85 +++++++++++++++++++ doc/source/solihull_gov_uk.md | 53 ++++++++++++ info.md | 2 +- 4 files changed, 140 insertions(+), 1 deletion(-) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/solihull_gov_uk.py create mode 100644 doc/source/solihull_gov_uk.md diff --git a/README.md b/README.md index 16e6ec385..67cd94700 100644 --- a/README.md +++ b/README.md @@ -1279,6 +1279,7 @@ Waste collection schedules in the following formats and countries are supported. - [Crawley Borough Council (myCrawley)](/doc/source/crawley_gov_uk.md) / crawley.gov.uk - [Croydon Council](/doc/source/croydon_gov_uk.md) / croydon.gov.uk - [Denbighshire County Council](/doc/source/denbighshire_gov_uk.md) / denbighshire.gov.uk +- [Denbighshire County Council](/doc/source/solihull_gov_uk.md) / denbighshire.gov.uk - [Derby City Council](/doc/source/derby_gov_uk.md) / derby.gov.uk - [Dudley Metropolitan Borough Council](/doc/source/dudley_gov_uk.md) / dudley.gov.uk - [Durham County Council](/doc/source/durham_gov_uk.md) / durham.gov.uk diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/solihull_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/solihull_gov_uk.py new file mode 100644 index 000000000..7eceb7619 --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/solihull_gov_uk.py @@ -0,0 +1,85 @@ +import logging +from datetime import datetime, timedelta + +import requests +from bs4 import BeautifulSoup +from waste_collection_schedule import Collection # type: ignore[attr-defined] + +_LOGGER = logging.getLogger(__name__) + +TITLE = "Denbighshire County Council" +DESCRIPTION = "Source for Denbighshire County Council." +URL = "https://www.denbighshire.gov.uk/" +TEST_CASES = { + "100070994046": {"uprn": 100070994046}, + "200003821723, Predict": {"uprn": 200003821723, "predict": True}, +} + +ICON_MAP = { + "garden waste": "mdi:leaf", + "household waste": "mdi:trash-can", + "mixed recycling": "mdi:recycle", +} + +API_URL = "https://digital.solihull.gov.uk/BinCollectionCalendar/Calendar.aspx" + + +class Source: + def __init__(self, uprn: str | int, predict: bool = False): + self._uprn: str | int = uprn + self._predict = predict + + def fetch(self) -> list[Collection]: + params = {"UPRN": self._uprn} + r = requests.get(API_URL, params=params) + r.raise_for_status() + + soup = BeautifulSoup(r.text, "html.parser") + + entries = [] + for card in soup.find_all("div", class_="card-title"): + bin_type_tag = card.find("h5") or card.find("h4") + bin_type = bin_type_tag.text + icon = ICON_MAP.get(bin_type.lower()) + + siblings = card.find_next_siblings("div", class_="mt-1") + for sibling in siblings: + date_tag = sibling.find("strong") + if not date_tag: + continue + date_str = date_tag.text + # Wednesday, 19 June 2024 + try: + date = datetime.strptime(date_str, "%A, %d %B %Y").date() + except ValueError: + _LOGGER.warning(f"Could not parse date {date_str}") + continue + entries.append(Collection(date=date, t=bin_type, icon=icon)) + + if "next" in sibling.text and self._predict: + try: + # card sibling with no class + freq_str = card.find_next_sibling() + if not ( + "every other week" in freq_str.text.lower() + or "every week" in freq_str.text.lower() + ): + _LOGGER.info( + f"Skipping predikt (unknown frequency) for {freq_str.text}" + ) + continue + + freq = 2 if "every other week" in freq_str.text.lower() else 1 + for i in range(1, 10 // freq): + entries.append( + Collection( + date=date + timedelta(weeks=i * freq), + t=bin_type, + icon=icon, + ) + ) + except Exception as e: + _LOGGER.warning(f"Error predicting next collection: {e}") + pass + + return entries diff --git a/doc/source/solihull_gov_uk.md b/doc/source/solihull_gov_uk.md new file mode 100644 index 000000000..949988819 --- /dev/null +++ b/doc/source/solihull_gov_uk.md @@ -0,0 +1,53 @@ +# Solihull + +Waste collection schedules provided by [Solihull](https://www.solihull.gov.uk/). + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: solihull_gov_uk + args: + uprn: UPNR + predict: PREDICT +``` + +### Configuration Variables + +**uprn** +*(string|integer) (required)* + +**predict** +*(bool) (optional, default=False)* +*predict the next 10 weeks of collection dates based on the next collection date and the frequency of collections (only returns the next collection date if set to False)* + +## Example + +### Example 1 + +```yaml +waste_collection_schedule: + sources: + - name: solihull_gov_uk + args: + uprn: 100070994046 +``` + +### Example with prediction + +```yaml +waste_collection_schedule: + sources: + - name: solihull_gov_uk + args: + uprn: 200003821723 + predict: True +``` + + +## How to get your UPRN + +You can see the uprn in the address bar after searching your address in the [Solihull Council Bincollection Form](https://digital.solihull.gov.uk/BinCollectionCalendar/). + +another easy way to discover your Unique Property Reference Number (UPRN) is by going to and entering in your address details. diff --git a/info.md b/info.md index b8d18a1f2..529bfba4a 100644 --- a/info.md +++ b/info.md @@ -36,7 +36,7 @@ Waste collection schedules from service provider web sites are updated daily, de | Slovenia | Moji odpadki, Ljubljana | | Sweden | Affärsverken, Gästrike Återvinnare, Jönköping - June Avfall & Miljö, Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Linköping - Tekniska Verken, Lund Waste Collection, North / Middle Bohuslän - Rambo AB, 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, VIVAB Sophämtning | | Switzerland | A-Region, Alchenstorf, Andwil, Appenzell, Berg, Bühler, Canton of Zürich, Eggersriet, Gais, Gaiserwald, Goldach, Grosswangen, Grub, Heiden, Herisau, Horn, Hundwil, Häggenschwil, Lindau, Lutzenberg, Muolen, Mörschwil, Münchenstein, Münsingen BE, Switzerland, 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, Adur & Worthing Councils, Allerdale Borough Council, Amber Valley Borough Council, Anglesey, Ards and North Down Borough Council, Ashfield District Council, Ashford Borough Council, Aylesbury Vale District Council, Barnsley Metropolitan Borough Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, BCP Council, Bedford Borough Council, Binzone, Birmingham City Council, Blackburn with Darwen Borough Council, Blackpool Council, Borough Council of King's Lynn & West Norfolk, Borough of Broxbourne Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District Council, Bromsgrove City Council, Broxtowe Borough Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Burnley Council, Bury Council, Cambridge City Council, Canterbury City Council, Cardiff Council, Central Bedfordshire Council, Cherwell District Council, Cheshire East Council, Cheshire West and Chester Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City Of Lincoln Council, City of York Council, Colchester City Council, Conwy County Borough Council, Cornwall Council, Crawley Borough Council (myCrawley), Croydon Council, Denbighshire County Council, Derby City Council, Dudley Metropolitan Borough Council, Durham County Council, East Ayrshire Council, East Cambridgeshire District Council, East Devon District Council, East Herts Council, East Northamptonshire and Wellingborough, East Renfrewshire Council, East Riding of Yorkshire Council, Eastbourne Borough Council, Eastleigh Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Falkirk, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Flintshire, Fylde Council, Gateshead Council, Gedling Borough Council (unofficial), Glasgow City Council, Guildford Borough Council, Gwynedd, Harborough District Council, Haringey Council, Harlow Council, Hart District Council, Herefordshire City Council, Highland, Horsham District Council, Hull City Council, Huntingdonshire District Council, iTouchVision, Joint Waste Solutions, Kirklees Council, Lancaster City Council, Leicester City Council, Lewes District Council, Lichfield District Council, Lisburn and Castlereagh City Council, Liverpool City Council, London Borough of Barking and Dagenham, London Borough of Bexley, London Borough of Bromley, London Borough of Camden, London Borough of Harrow, London Borough of Hounslow, London Borough of Lewisham, London Borough of Merton, London Borough of Newham, Maidstone Borough Council, Maldon District Council, Manchester City Council, Mansfield District Council, Mendip District Council, Mid-Sussex District Council, Middlesbrough Council, Milton Keynes council, Moray Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Ayrshire Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Northamptonshire council, North Somerset Council, North West Leicestershire District Council, North Yorkshire Council - Hambleton, North Yorkshire Council - Harrogate, North Yorkshire Council - Scarborough, North Yorkshire Council - Selby, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough Council, Renfrewshire 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, Shropshire 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 Kesteven District Council, South Norfolk Council, South Oxfordshire District Council, South Somerset District Council, South Tyneside Council, Southampton City Council, Stafford Borough Council, Stevenage Borough Council, Stirling.gov.uk, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, Sutton Council, London, Swansea Council, Swindon Borough Council, Tameside Metropolitan Borough Council, Telford and Wrekin Council, Test Valley Borough Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, Tunbridge Wells, UK Bin Collection Schedule (UKBCD) project, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Warrington Borough Council, Warwick District Council, Waverley Borough Council, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, West Northamptonshire council, West Suffolk Council, Westmorland & Furness Council, Barrow area, Westmorland & Furness Council, South Lakeland area, Wigan Council, Wiltshire Council, Windsor and Maidenhead, Wirral Council, Woking Borough Council, Wokingham Borough Council, Wychavon District Council, Wyre Forest District Council | +| United Kingdom | Aberdeenshire Council, Adur & Worthing Councils, Allerdale Borough Council, Amber Valley Borough Council, Anglesey, Ards and North Down Borough Council, Ashfield District Council, Ashford Borough Council, Aylesbury Vale District Council, Barnsley Metropolitan Borough Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, BCP Council, Bedford Borough Council, Binzone, Birmingham City Council, Blackburn with Darwen Borough Council, Blackpool Council, Borough Council of King's Lynn & West Norfolk, Borough of Broxbourne Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Bristol City Council, Broadland District Council, Bromsgrove City Council, Broxtowe Borough Council, Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas, Burnley Council, Bury Council, Cambridge City Council, Canterbury City Council, Cardiff Council, Central Bedfordshire Council, Cherwell District Council, Cheshire East Council, Cheshire West and Chester Council, Chesterfield Borough Council, Chichester District Council, City of Doncaster Council, City Of Lincoln Council, City of York Council, Colchester City Council, Conwy County Borough Council, Cornwall Council, Crawley Borough Council (myCrawley), Croydon Council, Denbighshire County Council, Denbighshire County Council, Derby City Council, Dudley Metropolitan Borough Council, Durham County Council, East Ayrshire Council, East Cambridgeshire District Council, East Devon District Council, East Herts Council, East Northamptonshire and Wellingborough, East Renfrewshire Council, East Riding of Yorkshire Council, Eastbourne Borough Council, Eastleigh Borough Council, Elmbridge Borough Council, Environment First, Exeter City Council, Falkirk, Fareham Council, FCC Environment, Fenland District Council, Fife Council, Flintshire, Fylde Council, Gateshead Council, Gedling Borough Council (unofficial), Glasgow City Council, Guildford Borough Council, Gwynedd, Harborough District Council, Haringey Council, Harlow Council, Hart District Council, Herefordshire City Council, Highland, Horsham District Council, Hull City Council, Huntingdonshire District Council, iTouchVision, Joint Waste Solutions, Kirklees Council, Lancaster City Council, Leicester City Council, Lewes District Council, Lichfield District Council, Lisburn and Castlereagh City Council, Liverpool City Council, London Borough of Barking and Dagenham, London Borough of Bexley, London Borough of Bromley, London Borough of Camden, London Borough of Harrow, London Borough of Hounslow, London Borough of Lewisham, London Borough of Merton, London Borough of Newham, Maidstone Borough Council, Maldon District Council, Manchester City Council, Mansfield District Council, Mendip District Council, Mid-Sussex District Council, Middlesbrough Council, Milton Keynes council, Moray Council, Newcastle City Council, Newcastle Under Lyme Borough Council, Newport City Council, North Ayrshire Council, North Herts Council, North Kesteven District Council, North Lincolnshire Council, North Northamptonshire council, North Somerset Council, North West Leicestershire District Council, North Yorkshire Council - Hambleton, North Yorkshire Council - Harrogate, North Yorkshire Council - Scarborough, North Yorkshire Council - Selby, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough Council, Renfrewshire 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, Shropshire 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 Kesteven District Council, South Norfolk Council, South Oxfordshire District Council, South Somerset District Council, South Tyneside Council, Southampton City Council, Stafford Borough Council, Stevenage Borough Council, Stirling.gov.uk, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, Sutton Council, London, Swansea Council, Swindon Borough Council, Tameside Metropolitan Borough Council, Telford and Wrekin Council, Test Valley Borough Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Tonbridge and Malling Borough Council, Tunbridge Wells, UK Bin Collection Schedule (UKBCD) project, Uttlesford District Council, Vale of White Horse District Council, Walsall Council, Warrington Borough Council, Warwick District Council, Waverley Borough Council, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, West Northamptonshire council, West Suffolk Council, Westmorland & Furness Council, Barrow area, Westmorland & Furness Council, South Lakeland area, Wigan Council, Wiltshire Council, Windsor and Maidenhead, Wirral Council, Woking Borough Council, Wokingham Borough Council, Wychavon District Council, Wyre Forest District Council | | United States of America | Albuquerque, New Mexico, USA, City of Austin, TX, 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 |