From 8e5aba0851527d5179da09a9236fc999ac694e17 Mon Sep 17 00:00:00 2001 From: Garry Mitchell Date: Mon, 16 Jan 2023 16:47:09 +0000 Subject: [PATCH] Add East Cambs District Council --- README.md | 1 + .../source/eastcambs_gov_uk.py | 55 +++++++++++++++++++ doc/source/eastcambs_gov_uk.md | 34 ++++++++++++ info.md | 2 +- 4 files changed, 91 insertions(+), 1 deletion(-) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/eastcambs_gov_uk.py create mode 100644 doc/source/eastcambs_gov_uk.md diff --git a/README.md b/README.md index 4ccf92c6..b7630d3c 100644 --- a/README.md +++ b/README.md @@ -360,6 +360,7 @@ Waste collection schedules in the following formats and countries are supported. - [Cornwall Council](/doc/source/cornwall_gov_uk.md) / cornwall.gov.uk - [Derby City Council](/doc/source/derby_gov_uk.md) / derby.gov.uk - [Eastbourne Borough Council](/doc/source/environmentfirst_co_uk.md) / lewes-eastbourne.gov.uk +- [East Cambridgeshire District Council](/doc/source/eastcambs_gov_uk.md) / eastcambs.gov.uk - [East Herts Council](/doc/source/eastherts_gov_uk.md) / eastherts.gov.uk - [Elmbridge Borough Council](/doc/source/elmbridge_gov_uk.md) / elmbridge.gov.uk - [Environment First](/doc/source/environmentfirst_co_uk.md) / environmentfirst.co.uk diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/eastcambs_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/eastcambs_gov_uk.py new file mode 100644 index 00000000..4b33842e --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/eastcambs_gov_uk.py @@ -0,0 +1,55 @@ +import datetime + +from bs4 import BeautifulSoup +import requests +from waste_collection_schedule import Collection + +TITLE = "East Cambridgeshire District Council" +DESCRIPTION = "Source for eastcambs.gov.uk, East Cambridgeshire District Council, UK" +URL = "https://www.eastcambs.gov.uk" +TEST_CASES = { + "East Cambridgeshire District Council, CB7 4EE": {"uprn": 10002597178}, +} + +API_URL = "https://eastcambs-self.achieveservice.com/appshost/firmstep/self/apps/custompage/bincollections?uprn={uprn}" + +ICON_MAP = { + "Black Bag": "mdi:trash-can", + "Blue Bin": "mdi:recycle", + "Green or Brown Bin": "mdi:leaf", +} + + +class Source: + def __init__(self, uprn=None): + self._uprn = uprn + + def fetch(self): + q = str(API_URL).format(uprn=self._uprn) + + r = requests.get(q) + r.raise_for_status() + + responseContent = r.text + + entries = [] + + soup = BeautifulSoup(responseContent, "html.parser") + x = soup.findAll("div", {"class": "row collectionsrow"}) + + for row in x: + fields = row.findChildren() + if fields[0].text.strip() == "Please select an address to view the upcoming collections.": + continue + + entries.append( + Collection( + date=datetime.datetime.strptime( + fields[3].text, "%a - %d %b %Y" + ).date(), + t=fields[2].text, + icon=ICON_MAP.get(fields[2].text), + ) + ) + + return entries diff --git a/doc/source/eastcambs_gov_uk.md b/doc/source/eastcambs_gov_uk.md new file mode 100644 index 00000000..8b9dfcef --- /dev/null +++ b/doc/source/eastcambs_gov_uk.md @@ -0,0 +1,34 @@ +# East Cambridgeshire District Council + +Support for schedules provided by [East Cambridgeshire District Council](https://www.eastcambs.gov.uk/), serving East Cambridgeshrire district, UK. + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: eastcambs_gov_uk + args: + uprn: UNIQUE_PROPERTY_REFERENCE_NUMBER +``` + +### Configuration Variables + +### 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. +Otherwise you can inspect the web requests the East Cambridgeshire District Council website makes when entering in your postcode and then selecting your address. + +## Example +```yaml +waste_collection_schedule: + sources: + - name: eastcambs_gov_uk + args: + uprn: 10002597178 +``` \ No newline at end of file diff --git a/info.md b/info.md index c3501991..3b41c642 100644 --- a/info.md +++ b/info.md @@ -28,7 +28,7 @@ Waste collection schedules from service provider web sites are updated daily, de | Poland | Ecoharmonogram, Warsaw | | Sweden | Landskrona - Svalövs Renhållning, Lerum Vatten och Avlopp, Ronneby Miljöteknik, 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 | Ashfield District 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, City of York Council, Colchester Borough Council, Cornwall Council, Derby City Council, Eastbourne Borough Council, East Herts Council, Elmbridge Borough Council, Environment First, FCC Environment, Guildford Borough Council, Harborough District Council, Harlow Council, Horsham District Council, Huntingdonshire District Council, Lewes District Council, London Borough of Lewisham, Manchester City Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, North Somerset Council, Nottingham City Council, Peterborough City Council, Richmondshire District Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Hams District Council, South Norfolk and Broadland Council, Southampton City Council, Stevenage Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Walsall Council, Waverley Borough Council, West Berkshire Council, West Devon Borough Council, Wiltshire Council, Wyre Forest District Council | +| United Kingdom | Ashfield District 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, City of York Council, Colchester Borough Council, Cornwall Council, Derby City Council, Eastbourne Borough Council, East Cambridgeshire District Council, East Herts Council, Elmbridge Borough Council, Environment First, FCC Environment, Guildford Borough Council, Harborough District Council, Harlow Council, Horsham District Council, Huntingdonshire District Council, Lewes District Council, London Borough of Lewisham, Manchester City Council, Middlesbrough Council, Newcastle City Council, Newcastle Under Lyme Borough Council, North Somerset Council, Nottingham City Council, Peterborough City Council, Richmondshire District Council, Rushmoor Borough Council, Salford City Council, Sheffield City Council, South Cambridgeshire District Council, South Hams District Council, South Norfolk and Broadland Council, Southampton City Council, Stevenage Borough Council, Telford and Wrekin Council, Tewkesbury Borough Council, The Royal Borough of Kingston 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 |