diff --git a/README.md b/README.md index 05bca99e..3661f84f 100644 --- a/README.md +++ b/README.md @@ -1223,6 +1223,7 @@ Waste collection schedules in the following formats and countries are supported. - [Breckland Council](/doc/source/breckland_gov_uk.md) / breckland.gov.uk/mybreckland - [Bristol City Council](/doc/source/bristol_gov_uk.md) / bristol.gov.uk - [Broadland District Council](/doc/source/south_norfolk_and_broadland_gov_uk.md) / area.southnorfolkandbroadland.gov.uk +- [Bromsgrove City Council](/doc/source/bromsgrove_gov_uk.md) / bromsgrove.gov.uk - [Broxtowe Borough Council](/doc/source/broxtowe_gov_uk.md) / broxtowe.gov.uk - [Buckinghamshire Waste Collection - Former Chiltern, South Bucks or Wycombe areas](/doc/source/chiltern_gov_uk.md) / chiltern.gov.uk - [Burnley Council](/doc/source/burnley_gov_uk.md) / burnley.gov.uk diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/bromsgrove_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/bromsgrove_gov_uk.py new file mode 100644 index 00000000..47efc364 --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/bromsgrove_gov_uk.py @@ -0,0 +1,94 @@ +from datetime import datetime + +import requests +from bs4 import BeautifulSoup +from waste_collection_schedule import Collection # type: ignore[attr-defined] + +TITLE = "Bromsgrove City Council" +DESCRIPTION = "Source for bromsgrove.gov.uk services for Bromsgrove, UK." +URL = "https://bromsgrove.gov.uk" +TEST_CASES = { + "Shakespeare House": {"uprn": "10094552413", "postcode": "B61 8DA"}, + "The Lodge": {"uprn": 10000218025, "postcode": "B60 2AA"}, + "Ceader Lodge": {"uprn": 100120576392, "postcode": "B60 2JS"}, + "Finstall Road": {"uprn": 100120571971, "postcode": "B60 3DE"}, +} + +HEADERS = { + "User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_5) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/50.0.2661.102 Safari/537.36", +} + +API_URLS = { + "collection": "https://bincollections.bromsgrove.gov.uk/BinCollections/Details/", +} +ICON_MAP = { + "Grey": "mdi:trash-can", + "Green": "mdi:recycle", + "Brown": "mdi:leaf", +} + + +class Source: + def __init__(self, uprn: str, postcode: str): + self._uprn = uprn + self._postcode = "".join(postcode.split()).upper() + + def fetch(self): + entries: list[Collection] = [] + + session = requests.Session() + session.headers.update(HEADERS) + + form_data = {"UPRN": self._uprn} + + collection_response = session.post(API_URLS["collection"], data=form_data) + + # Parse HTML + soup = BeautifulSoup(collection_response.text, "html.parser") + + # Find postcode + postcode = "".join(soup.find("h3").text.split()[-2:]).upper() + + # Find bins and their collection details + bins = soup.find_all(class_="collection-container") + + # Initialize lists to store extracted information + bin_info = [] + + # Extract information for each bin + for bin in bins: + bin_name = bin.find(class_="heading").text.strip() + bin_color = bin.find("img")["alt"] + collection_dates = [] + collection_details = bin.find_all(class_="caption") + for detail in collection_details: + date_string = detail.text.split()[-3:] + collection_date = " ".join(date_string) + collection_dates.append( + datetime.strptime(collection_date, "%d %B %Y").date() + ) + bin_info.append( + { + "Bin Name": bin_name, + "Bin Color": bin_color, + "Collection Dates": collection_dates, + } + ) + + # Check if the postcode matches the one provided, otherwise don't fill in the output + if postcode == self._postcode: + for info in bin_info: + entries.append( + Collection( + date=info["Collection Dates"][0], + t=info["Bin Name"], + icon=ICON_MAP.get(info["Bin Color"], "mdi:help"), + ) + ) + + if not entries: + raise ValueError( + "Could not get collections for the given combination of UPRN and Postcode." + ) + + return entries diff --git a/doc/source/bromsgrove_gov_uk.md b/doc/source/bromsgrove_gov_uk.md new file mode 100644 index 00000000..d00280e6 --- /dev/null +++ b/doc/source/bromsgrove_gov_uk.md @@ -0,0 +1,55 @@ +# Bromsgrove District Council + +Support for schedules provided by [Bromsgrove District Council](https://www.bromsgrove.gov.uk/), in the UK. + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: bromsgrove_gov_uk + args: + uprn: UNIQUE_PROPERTY_REFERENCE_NUMBER + postcode: POSTCODE +``` + +### Configuration Variables + +**uprn** +*(string)* + +The "Unique Property Reference Number" for your address. You can find it by searching for your address at . + +**postcode** +*(string)* + +The Post Code for your address. This needs to match the postcode corresponding to your UPRN. + +## Example + +```yaml +waste_collection_schedule: + sources: + - name: bromsgrove_gov_uk + args: + uprn: 10094552413 + postcode: B61 8DA +``` + +## Returned Collections + +This source will return the next collection date for each container type. + +## Returned collection types + +### Household Collection + +Grey bin is for general waste. + +### Recycling Collection + +Green bin is for dry recycling (metals, glass, plastics, paper and card). + +### Garden waste Chargeable Collections + +Brown bin if for gareden waste. This is a annual chargable service. diff --git a/info.md b/info.md index d736066c..b4c559ec 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, 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, 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, Glasgow City Council, Guildford Borough Council, Gwynedd, Harborough District Council, Haringey Council, Harlow Council, Hart District Council, Herefordshire City Council, Highland, Horsham District 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 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, Wyre Forest District Council | +| United Kingdom | Aberdeenshire Council, Adur & Worthing Councils, Allerdale Borough Council, Amber Valley Borough Council, Anglesey, 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, Glasgow City Council, Guildford Borough Council, Gwynedd, Harborough District Council, Haringey Council, Harlow Council, Hart District Council, Herefordshire City Council, Highland, Horsham District 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 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, 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 |