Skip to content

Commit

Permalink
Added support for the London Borough of Newham (#1863)
Browse files Browse the repository at this point in the history
* Added support for the London Borough of Newham

* Fixed issue with datetime parsing in newham.gov.uk

* refactoring + allow integer uprn update documentation

---------

Co-authored-by: 5ila5 <[email protected]>
  • Loading branch information
richkershaw and 5ila5 authored Mar 4, 2024
1 parent 9ed52d6 commit 5d88326
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1261,6 +1261,7 @@ Waste collection schedules in the following formats and countries are supported.
- [London Borough of Hounslow](/doc/source/hounslow_gov_uk.md) / hounslow.gov.uk
- [London Borough of Lewisham](/doc/source/lewisham_gov_uk.md) / lewisham.gov.uk
- [London Borough of Merton](/doc/source/merton_gov_uk.md) / merton.gov.uk
- [London Borough of Newham](/doc/source/newham_gov_uk.md) / newham.gov.uk
- [Maidstone Borough Council](/doc/source/maidstone_gov_uk.md) / maidstone.gov.uk
- [Maldon District Council](/doc/source/maldon_gov_uk.md) / maldon.gov.uk
- [Manchester City Council](/doc/source/manchester_uk.md) / manchester.gov.uk
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
from datetime import datetime

import requests
from bs4 import BeautifulSoup
from waste_collection_schedule import Collection # type: ignore[attr-defined]

TITLE = "London Borough of Newham"
DESCRIPTION = "Source for newham.gov.uk services for London Borough of Newham, UK."
URL = "https://www.newham.gov.uk"
TEST_CASES = {
"Test_001": {"property": "000046029461"},
"Test_002": {"property": "000046250697"},
"Test_003": {"property": 46012509},
}

ICON_MAP = {"DOMESTIC": "mdi:trash-can", "RECYCLING": "mdi:glass-fragile"}


class Source:
def __init__(self, property):
self._property = str(property).zfill(12)

def fetch(self):
s = requests.Session()
r = s.get(f"https://bincollection.newham.gov.uk/Details/Index/{self._property}")

# Make a BS4 object
soup = BeautifulSoup(r.text, features="html.parser")
soup.prettify()

# Form an array for the bins
entries = []

# Find section with bins in
sections = soup.find_all("div", {"class": "card h-100"})

# there may also be a recycling one too
sections_recycling = soup.find_all(
"div", {"class": "card h-100 card-recycling"}
)
if len(sections_recycling) > 0:
sections.append(sections_recycling[0])

# For each bin section, get the text and the list elements
for item in sections:
header = item.find("div", {"class": "card-header"})
bin_type_element = header.find_next("b")
if bin_type_element is None:
continue
bin_type = bin_type_element.text
array_expected_types = ["Domestic", "Recycling"]
if bin_type not in array_expected_types:
continue
date_string = (
item.find_next("p", {"class": "card-text"})
.find_next("mark")
.next_sibling.strip()
)
next_collection = datetime.strptime(date_string, "%d/%m/%Y").date()

entries.append(
Collection(
date=next_collection,
t=bin_type,
icon=ICON_MAP.get(bin_type.split(" ")[0].upper()),
)
)

return entries
39 changes: 39 additions & 0 deletions doc/source/newham_gov_uk.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# London Borough of Newham

Support for schedules provided by the [London Borough of Newham](https://www.newham.gov.uk), serving Newham, UK.

## Configuration via configuration.yaml

```yaml
waste_collection_schedule:
sources:
- name: newham_gov_uk
args:
property: PROPERTY_ID
```
### Configuration Variables
**property**<br>
*(string) (required)*
Unique number the London Borough of Newham uses to identify your property.
#### How to find your `PROPERTY_ID`

Searach for your waste collection schedule at (https://bincollection.newham.gov.uk/). Your `PROPERTY_ID` is the set of numbers at the end of the url when your schedule is being displayed.

For example: https://bincollection.newham.gov.uk/Details/Index/000046029438

You can also find your `PROPERTY_ID`/`UPRN` by going to <https://www.findmyaddress.co.uk/> and entering in your address details.

## Example

```yaml
waste_collection_schedule:
sources:
- name: newham_gov_uk
args:
property: "000046029438"
```
2 changes: 1 addition & 1 deletion info.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,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 |
| 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, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Blackpool Council, Borough Council of King's Lynn & West Norfolk, 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, 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 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, Elmbridge Borough Council, Environment First, Exeter City Council, Falkirk, Fareham Council, FCC Environment, Fenland District Council, Fife Council, 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, 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 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 - Selby, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough 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, Stevenage Borough Council, Stirling.gov.uk, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, 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 Suffolk Council, 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, Bedford Borough Council, Binzone, Blackburn with Darwen Borough Council, Blackpool Council, Borough Council of King's Lynn & West Norfolk, 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, 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 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, Elmbridge Borough Council, Environment First, Exeter City Council, Falkirk, Fareham Council, FCC Environment, Fenland District Council, Fife Council, 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 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 - Selby, Nottingham City Council, Oxford City Council, Peterborough City Council, Portsmouth City Council, Reading Council, Redbridge Council, Reigate & Banstead Borough 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, Stevenage Borough Council, Stirling.gov.uk, Stockport Council, Stockton-on-Tees Borough Council, Stoke-on-Trent, Stratford District Council, Surrey Heath Borough Council, 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 Suffolk Council, 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 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 |
<!--End of country section-->

Expand Down

0 comments on commit 5d88326

Please sign in to comment.