-
-
Notifications
You must be signed in to change notification settings - Fork 658
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added support for the London Borough of Newham (#1863)
* 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
1 parent
9ed52d6
commit 5d88326
Showing
4 changed files
with
110 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 69 additions & 0 deletions
69
...om_components/waste_collection_schedule/waste_collection_schedule/source/newham_gov_uk.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters