From bb4d5c8791ca0a111c533a2eb5d71ee8deb4a9b5 Mon Sep 17 00:00:00 2001 From: Colin Barker Date: Wed, 4 Jan 2023 17:12:51 +0000 Subject: [PATCH] Added Horsham District Council --- README.md | 1 + .../source/horsham_gov_uk.py | 58 +++++++++++++++++++ doc/source/horsham_gov_uk.md | 32 ++++++++++ info.md | 2 +- 4 files changed, 92 insertions(+), 1 deletion(-) create mode 100644 custom_components/waste_collection_schedule/waste_collection_schedule/source/horsham_gov_uk.py create mode 100644 doc/source/horsham_gov_uk.md diff --git a/README.md b/README.md index b3ba87705..14de3bf03 100644 --- a/README.md +++ b/README.md @@ -279,6 +279,7 @@ Waste collection schedules in the following formats and countries are supported. - [FCC Environment](/doc/source/fccenvironment_co_uk.md) / fccenvironment.co.uk - [Guildford Borough Council](/doc/source/guildford_gov_uk.md) / guildford.gov.uk - [Harborough District Council](/doc/source/fccenvironment_co_uk.md) / harborough.gov.uk +- [Horsham District Council](/doc/source/horsham_gov_uk.md) / horsham.gov.uk - [Huntingdonshire District Council](/doc/source/huntingdonshire_gov_uk.md) / huntingdonshire.gov.uk - [Lewes District Council](/doc/source/environmentfirst_co_uk.md) / lewes-eastbourne.gov.uk - [London Borough of Lewisham](/doc/source/lewisham_gov_uk.md) / lewisham.gov.uk diff --git a/custom_components/waste_collection_schedule/waste_collection_schedule/source/horsham_gov_uk.py b/custom_components/waste_collection_schedule/waste_collection_schedule/source/horsham_gov_uk.py new file mode 100644 index 000000000..2e0bc555e --- /dev/null +++ b/custom_components/waste_collection_schedule/waste_collection_schedule/source/horsham_gov_uk.py @@ -0,0 +1,58 @@ +import logging +from datetime import datetime +from waste_collection_schedule import Collection + +import requests +from bs4 import BeautifulSoup + +TITLE = "Horsham District Council" +DESCRIPTION = "Source script for Horsham District Council" +URL = "https://www.horsham.gov.uk" +TEST_CASES = { + "Blackthorn Avenue - number": {"uprn": 10013792881}, + "Blackthorn Avenue - string": {"uprn": "10013792881"} +} +API_URL = "https://satellite.horsham.gov.uk/environment/refuse/cal_details.asp" +ICON_MAP = { + "Refuse Bin for Non-Recycling": "mdi:trash-can", + "Blue-Top Bin for Recycling": "mdi:recycle", + "Brown-Top Bin for Garden Waste": "mdi:leaf", +} +HEADERS = { + "user-agent": "Mozilla/5.0", +} +_LOGGER = logging.getLogger(__name__) + +class Source: + def __init__(self, uprn: str): + self._uprn = str(uprn) + + def fetch(self): + entries = [] + + r = requests.post( + API_URL, + data={"uprn": self._uprn}, + ) + + soup = BeautifulSoup(r.text, features="html.parser") + results = soup.find_all("tr") + + for result in results: + result_row = result.find_all("td") + if len(result_row) == 0: # This removes the first header row, or any rows with no data + continue + else: + date = datetime.strptime(result_row[1].text, "%d/%m/%Y").date() # Pull out the rows date + + collection_text = result_row[2].text.replace(u'\xa0', u' ') # This is to remove a non-blanking space + collection_items = collection_text.split("AND") # Sometimes there will be multiple bins, split with the word AND + for collection_type in collection_items: + entries.append( + Collection( + date=date, + t=collection_type.strip(), # Strip added to remove trailing white space + icon=ICON_MAP[collection_type.strip()] # Strip added to remove trailing white space + ) + ) + return entries \ No newline at end of file diff --git a/doc/source/horsham_gov_uk.md b/doc/source/horsham_gov_uk.md new file mode 100644 index 000000000..5251f3f71 --- /dev/null +++ b/doc/source/horsham_gov_uk.md @@ -0,0 +1,32 @@ +# Horsham District Council + +Support for schedules provided by [Horsham District Council](https://www.horsham.gov.uk/waste-recycling-and-bins/household-bin-collections/check-your-bin-collection-day). + +## Configuration via configuration.yaml + +```yaml +waste_collection_schedule: + sources: + - name: horsham_gov_uk + args: + uprn: UPRN_CODE +``` + +### Configuration Variables + +**uprn** +_(string) (required)_ + +## Example using UPRN + +```yaml +waste_collection_schedule: + sources: + - name: horsham_gov_uk + args: + uprn: "10013792881" +``` + +## How to get the source argument + +An easy way to find 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 cebebd156..3db97c08c 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 | 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, Grub, Heiden, Herisau, Horn, Hundwil, Häggenschwil, Lindau, Lutzenberg, Muolen, Mörschwil, 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, Cheshire East Council, Chesterfield Borough Council, City of York Council, Colchester Borough Council, Cornwall Council, Derby City Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, FCC Environment, Guildford Borough Council, Harborough District Council, Huntingdonshire District Council, Lewes District Council, London Borough of Lewisham, Manchester City Council, Middlesbrough Council, Newcastle City 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, Stevenage Borough Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Walsall Council, West Berkshire Council, West Devon Borough Council, Wiltshire Council | +| United Kingdom | Ashfield District Council, Bracknell Forest Council, Bradford Metropolitan District Council, Braintree District Council, Breckland Council, Cambridge City Council, Canterbury City Council, Cheshire East Council, Chesterfield Borough Council, City of York Council, Colchester Borough Council, Cornwall Council, Derby City Council, Eastbourne Borough Council, Elmbridge Borough Council, Environment First, FCC Environment, Guildford Borough Council, Harborough District Council, Horsham District Council, Huntingdonshire District Council, Lewes District Council, London Borough of Lewisham, Manchester City Council, Middlesbrough Council, Newcastle City 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, Stevenage Borough Council, Tewkesbury Borough Council, The Royal Borough of Kingston Council, Walsall Council, West Berkshire Council, West Devon Borough Council, Wiltshire Council | | United States of America | City of Pittsburgh, Republic Services, Seattle Public Utilities |