From d8b0c0bd3c6e300ddef51c616871db495246cbf1 Mon Sep 17 00:00:00 2001 From: Paul Jones Date: Sun, 9 Jul 2023 20:40:09 +0100 Subject: [PATCH] Add new source for warrington.gov.uk --- README.md | 1 + .../source/warrington_gov_uk.py | 76 +++++++++++++++++++ doc/source/warrington_gov_uk.md | 31 ++++++++ info.md | 2 +- 4 files changed, 109 insertions(+), 1 deletion(-) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/warrington_gov_uk.py create mode 100644 doc/source/warrington_gov_uk.md diff --git a/README.md b/README.md index a0445d20..c5618125 100644 --- a/README.md +++ b/README.md @@ -811,6 +811,7 @@ Waste collection schedules in the following formats and countries are supported. - [Uttlesford District Council](/doc/source/uttlesford_gov_uk.md) / uttlesford.gov.uk - [Vale of White Horse District Council](/doc/source/binzone_uk.md) / whitehorsedc.gov.uk - [Walsall Council](/doc/source/walsall_gov_uk.md) / walsall.gov.uk +- [Warrington Borough Council](/doc/source/warrington_gov_uk.md) / warrington.gov.uk - [Waverley Borough Council](/doc/source/waverley_gov_uk.md) / waverley.gov.uk - [Wealden District Council](/doc/source/wealden_gov_uk.md) / wealden.gov.uk - [Welwyn Hatfield Borough Council](/doc/source/welhat_gov_uk.md) / welhat.gov.uk diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/warrington_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/warrington_gov_uk.py new file mode 100644 index 00000000..d03e4c66 --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/warrington_gov_uk.py @@ -0,0 +1,76 @@ +import requests +import json + +from datetime import datetime +from waste_collection_schedule import Collection # type: ignore[attr-defined] + +TITLE = "Warrington Borough Council" +DESCRIPTION = "Source for warrington.gov.uk services for Warrington Borough Council, UK." +URL = "https://www.warrington.gov.uk" + +TEST_CASES = { + "Test_001": {"uprn": "100010309878"}, + "Test_002": {"uprn": "100010296572"}, + "Test_003": {"uprn": 100010291332}, + "Test_004": {"uprn": 100010258176}, +} +HEADERS = { + "user-agent": "Mozilla/5.0", +} +ICON_MAP = { + "BLACK BIN": "mdi:trash-can", + "BLUE BIN": "mdi:recycle", + "GREEN BIN": "mdi:leaf", +} + + +class Source: + def __init__(self, uprn): + self._uprn = str(uprn).zfill(12) + + def fetch(self): + + s = requests.Session() + r = s.get(f"https://www.warrington.gov.uk/bin-collections/get-jobs/{self._uprn}", headers=HEADERS) + json_data = json.loads(r.text) + + entries = [] + + # If no schedule, return empty list. + if not json_data["schedule"]: + return entries + + for job in json_data["schedule"]: + # Data doesn't contain bin type, so we need to extract it from the job name. + bin_type = self.get_type(job["Name"]) + if not bin_type: + continue + + # List contains duplicates, so skip if already added. + if self.contains(entries, lambda x: x.date == datetime.strptime(job["ScheduledStart"], "%Y-%m-%dT%H:00:00").date() and x.type == bin_type): + continue + + entries.append( + Collection( + date=datetime.strptime(job["ScheduledStart"], "%Y-%m-%dT%H:00:00").date(), + t=bin_type, + icon=ICON_MAP.get(bin_type.upper()) + ) + ) + + return entries + + def get_type(self, name): + if "BLACK" in name: + return "Black Bin" + if "BLUE" in name: + return "Blue Bin" + if "GREEN" in name: + return "Green Bin" + return False + + def contains(self, list, filter): + for x in list: + if filter(x): + return True + return False diff --git a/doc/source/warrington_gov_uk.md b/doc/source/warrington_gov_uk.md new file mode 100644 index 00000000..a47ae215 --- /dev/null +++ b/doc/source/warrington_gov_uk.md @@ -0,0 +1,31 @@ +# Warrington Borough Council + +Support for schedules provided by [Warrington Borough Council](https://www.warrington.gov.uk/), serving Warrington Borough Council, UK. + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: warrington_gov_uk + args: + uprn: UNIQUE_PROPERTY_REFERENCE_NUMBER +``` + +### Configuration Variables + +**uprn**
+*(string) (required)* + + +#### How to find your `UPRN` +An easy way to discover your Unique Property Reference Number (UPRN) is by going to https://www.findmyaddress.co.uk/ and entering in your address details. + +## Example using UPRN +```yaml +waste_collection_schedule: + sources: + - name: warrington_gov_uk + args: + uprn: 100010309878 +``` diff --git a/info.md b/info.md index e309fe18..68edaa6d 100644 --- a/info.md +++ b/info.md @@ -30,7 +30,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, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough 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, Cambridge City Council, Canterbury City 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, Croydon Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, 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, Harborough District Council, Harlow Council, Herefordshire City Council, Horsham District Council, Huntingdonshire District Council, 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 Lewisham, London Borough of Merton, Maidstone Borough Council, 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 Kesteven District Council, North Lincolnshire Council, North Somerset Council, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushcliffe Brough Council, Rushmoor Borough Council, Salford City Council, Sheffield City 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 Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Swindon Borough Council, Telford and Wrekin 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, Waverley Borough Council, Wealden District Council, Welwyn Hatfield Borough Council, West Berkshire Council, West Devon Borough Council, West Dunbartonshire Council, Wigan Council, Wiltshire Council, Wirral Council, Wyre Forest District Council | +| United Kingdom | Aberdeenshire Council, Amber Valley Borough Council, Ashfield District Council, Ashford Borough Council, Basildon Council, Basingstoke and Deane Borough Council, Bath & North East Somerset Council, Bedford Borough Council, Binzone, Blackburn with Darwen Borough 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, Cambridge City Council, Canterbury City 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, Croydon Council, Derby City Council, East Cambridgeshire District Council, East Herts Council, East Northamptonshire and Wellingborough, 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, Harborough District Council, Harlow Council, Herefordshire City Council, Horsham District Council, Huntingdonshire District Council, 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 Lewisham, London Borough of Merton, Maidstone Borough Council, 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 Kesteven District Council, North Lincolnshire Council, North Somerset Council, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough Council, Richmondshire District Council, Rotherham Metropolitan Borough Council, Runnymede Borough Council, Rushcliffe Brough Council, Rushmoor Borough Council, Salford City Council, Sheffield City 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 Tyneside Council, Southampton City Council, Stevenage Borough Council, Stockport Council, Stockton-on-Tees Borough Council, Swindon Borough Council, Telford and Wrekin 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, Wirral Council, Wyre Forest District Council | | United States of America | Albuquerque, New Mexico, USA, 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 |