Skip to content

Commit

Permalink
Added Horsham District Council
Browse files Browse the repository at this point in the history
  • Loading branch information
mystcb committed Jan 4, 2023
1 parent 2fbb34d commit bb4d5c8
Show file tree
Hide file tree
Showing 4 changed files with 92 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
32 changes: 32 additions & 0 deletions doc/source/horsham_gov_uk.md
Original file line number Diff line number Diff line change
@@ -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 <https://www.findmyaddress.co.uk/> and entering in your address details.
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
<!--End of country section-->

Expand Down

0 comments on commit bb4d5c8

Please sign in to comment.