Skip to content

Commit a46ffb6

Browse files
committed
fix: Adding Hammersmith & Fulham
fix: robbrad#1504 - Adding Hammersmith & Fulham
1 parent ce62fa2 commit a46ffb6

3 files changed

Lines changed: 111 additions & 31 deletions

File tree

uk_bin_collection/tests/input.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1408,6 +1408,14 @@
14081408
"wiki_note": "Pass the UPRN. You can find it using [FindMyAddress](https://www.findmyaddress.co.uk/search).",
14091409
"LAD24CD": "E09000009"
14101410
},
1411+
"LondonBoroughHammersmithandFulham": {
1412+
"postcode": "W12 0BQ",
1413+
"url": "https://www.lbhf.gov.uk/",
1414+
"wiki_command_url_override": "https://www.lbhf.gov.uk/",
1415+
"wiki_name": "Hammersmith & Fulham",
1416+
"wiki_note": "Pass only the property postcode",
1417+
"LAD24CD": "E09000013"
1418+
},
14111419
"LondonBoroughHarrow": {
14121420
"uprn": "100021298754",
14131421
"url": "https://www.harrow.gov.uk",
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
from datetime import datetime
2+
3+
import requests
4+
from bs4 import BeautifulSoup
5+
6+
from uk_bin_collection.uk_bin_collection.common import *
7+
from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass
8+
9+
10+
# import the wonderful Beautiful Soup and the URL grabber
11+
class CouncilClass(AbstractGetBinDataClass):
12+
"""
13+
Concrete classes have to implement all abstract operations of the
14+
base class. They can also override some operations with a default
15+
implementation.
16+
"""
17+
18+
def parse_data(self, page: str, **kwargs) -> dict:
19+
20+
user_postcode = kwargs.get("postcode")
21+
check_uprn(user_postcode)
22+
bindata = {"bins": []}
23+
24+
user_postcode = user_postcode.strip().replace(" ", "")
25+
26+
URI = f"https://www.lbhf.gov.uk/bin-recycling-day/results?postcode={user_postcode}"
27+
UA = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/143.0.0.0 Safari/537.36"
28+
session = requests.session()
29+
session.headers.update({"User-Agent": UA})
30+
# Make the GET request
31+
response = session.get(URI)
32+
response.raise_for_status()
33+
34+
soup = BeautifulSoup(response.content, features="html.parser")
35+
results = soup.find("div", {"class": "nearest-search-results"})
36+
ol = results.find("ol")
37+
bin_collections = ol.find_all("a")
38+
for bin_collection in bin_collections:
39+
collection_day = bin_collection.get_text().split(" - ")[0]
40+
collection_type = bin_collection.get_text().split(" - ")[1]
41+
42+
if days_of_week.get(collection_day) == 0:
43+
collection_day = datetime.now().strftime(date_format)
44+
else:
45+
collection_day = get_next_day_of_week(collection_day)
46+
47+
dict_data = {
48+
"type": collection_type,
49+
"collectionDate": collection_day,
50+
}
51+
bindata["bins"].append(dict_data)
52+
53+
bindata["bins"].sort(
54+
key=lambda x: datetime.strptime(x.get("collectionDate"), "%d/%m/%Y")
55+
)
56+
57+
return bindata

wiki/Councils.md

Lines changed: 46 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -76,14 +76,12 @@ This document is still a work in progress, don't worry if your council isn't lis
7676
- [Chorley](#chorley)
7777
- [Colchester](#colchester)
7878
- [Conwy](#conwy)
79-
- [Copeland](#copeland)
8079
- [Cornwall](#cornwall)
8180
- [Cotswold](#cotswold)
8281
- [Coventry](#coventry)
8382
- [Crawley](#crawley)
8483
- [Croydon](#croydon)
8584
- [Cumberland](#cumberland)
86-
- [Cumberland](#cumberland)
8785
- [Dacorum](#dacorum)
8886
- [Darlington Borough Council](#darlington-borough-council)
8987
- [Dartford](#dartford)
@@ -111,6 +109,7 @@ This document is still a work in progress, don't worry if your council isn't lis
111109
- [East Staffordshire](#east-staffordshire)
112110
- [East Suffolk](#east-suffolk)
113111
- [Eastleigh](#eastleigh)
112+
- [Eden District (Westmorland and Furness)](#eden-district-(westmorland-and-furness))
114113
- [City of Edinburgh](#city-of-edinburgh)
115114
- [Elmbridge](#elmbridge)
116115
- [Enfield](#enfield)
@@ -171,7 +170,9 @@ This document is still a work in progress, don't worry if your council isn't lis
171170
- [City of Lincoln](#city-of-lincoln)
172171
- [Lisburn and Castlereagh](#lisburn-and-castlereagh)
173172
- [Liverpool](#liverpool)
173+
- [Camden](#camden)
174174
- [Ealing](#ealing)
175+
- [Hammersmith & Fulham](#hammersmith-&-fulham)
175176
- [Harrow](#harrow)
176177
- [Havering](#havering)
177178
- [Hounslow](#hounslow)
@@ -628,13 +629,14 @@ Note: You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/searc
628629

629630
### Bexley
630631
```commandline
631-
python collect_data.py BexleyCouncil https://waste.bexley.gov.uk/waste -s -u XXXXXXXX
632+
python collect_data.py BexleyCouncil https://waste.bexley.gov.uk/waste -s -u XXXXXXXX -w http://HOST:PORT/
632633
```
633634
Additional parameters:
634635
- `-s` - skip get URL
635636
- `-u` - UPRN
637+
- `-w` - remote Selenium web driver URL (required for Home Assistant)
636638

637-
Note: Provide your UPRN. Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to locate it.
639+
Note: Provide your UPRN. Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to locate it. This parser requires a Selenium webdriver.
638640

639641
---
640642

@@ -1156,17 +1158,6 @@ Note: Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your U
11561158

11571159
---
11581160

1159-
### Copeland
1160-
```commandline
1161-
python collect_data.py CopelandBoroughCouncil https://www.copeland.gov.uk -u XXXXXXXX
1162-
```
1163-
Additional parameters:
1164-
- `-u` - UPRN
1165-
1166-
Note: *****This has now been replaced by Cumberland Council****
1167-
1168-
---
1169-
11701161
### Cornwall
11711162
```commandline
11721163
python collect_data.py CornwallCouncil https://www.cornwall.gov.uk/my-area/ -s -u XXXXXXXX
@@ -1229,18 +1220,6 @@ Note: Pass the house number and postcode in their respective parameters. This pa
12291220

12301221
---
12311222

1232-
### Cumberland
1233-
```commandline
1234-
python collect_data.py CumberlandAllerdaleCouncil https://www.allerdale.gov.uk -p "XXXX XXX" -n XX
1235-
```
1236-
Additional parameters:
1237-
- `-p` - postcode
1238-
- `-n` - house number
1239-
1240-
Note: Pass the house number and postcode in their respective parameters.
1241-
1242-
---
1243-
12441223
### Cumberland
12451224
```commandline
12461225
python collect_data.py CumberlandCouncil https://www.cumberland.gov.uk/bins-recycling-and-street-cleaning/waste-collections/bin-collection-schedule -u XXXXXXXX
@@ -1579,6 +1558,17 @@ Note: Pass the UPRN. You can find it using [FindMyAddress](https://www.findmyadd
15791558

15801559
---
15811560

1561+
### Eden District (Westmorland and Furness)
1562+
```commandline
1563+
python collect_data.py EdenDistrictCouncil https://my.eden.gov.uk/myeden.aspx -u XXXXXXXX
1564+
```
1565+
Additional parameters:
1566+
- `-u` - UPRN
1567+
1568+
Note: For Eden area addresses within Westmorland and Furness. Provide your UPRN. You can find your UPRN using [FindMyAddress](https://www.findmyaddress.co.uk/search). Note: This returns collection days (e.g., 'Wednesday') rather than specific dates.
1569+
1570+
---
1571+
15821572
### City of Edinburgh
15831573
```commandline
15841574
python collect_data.py EdinburghCityCouncil https://www.edinburgh.gov.uk -s -p "XXXX XXX" -n XX
@@ -2314,6 +2304,19 @@ Note: You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/searc
23142304

23152305
---
23162306

2307+
### Camden
2308+
```commandline
2309+
python collect_data.py LondonBoroughCamdenCouncil https://environmentservices.camden.gov.uk/property -s -u XXXXXXXX -p "XXXX XXX"
2310+
```
2311+
Additional parameters:
2312+
- `-s` - skip get URL
2313+
- `-u` - UPRN
2314+
- `-p` - postcode
2315+
2316+
Note: Pass the property ID as UPRN. Find your property at https://www.camden.gov.uk/check-collection-day then use the property ID from the URL (e.g., https://environmentservices.camden.gov.uk/property/5063139).
2317+
2318+
---
2319+
23172320
### Ealing
23182321
```commandline
23192322
python collect_data.py LondonBoroughEaling https://www.ealing.gov.uk/site/custom_scripts/WasteCollectionWS/home/FindCollection -s -u XXXXXXXX
@@ -2326,6 +2329,17 @@ Note: Pass the UPRN. You can find it using [FindMyAddress](https://www.findmyadd
23262329

23272330
---
23282331

2332+
### Hammersmith & Fulham
2333+
```commandline
2334+
python collect_data.py LondonBoroughHammersmithandFulham https://www.lbhf.gov.uk/ -p "XXXX XXX"
2335+
```
2336+
Additional parameters:
2337+
- `-p` - postcode
2338+
2339+
Note: Pass only the property postcode
2340+
2341+
---
2342+
23292343
### Harrow
23302344
```commandline
23312345
python collect_data.py LondonBoroughHarrow https://www.harrow.gov.uk -u XXXXXXXX
@@ -3468,7 +3482,7 @@ Note: Follow the instructions [here](https://www.southlanarkshire.gov.uk/info/20
34683482

34693483
### South Norfolk
34703484
```commandline
3471-
python collect_data.py SouthNorfolkCouncil https://www.southnorfolkandbroadland.gov.uk/rubbish-recycling/south-norfolk-bin-collection-day-finder -s -u XXXXXXXX
3485+
python collect_data.py SouthNorfolkCouncil https://area.southnorfolkandbroadland.gov.uk/FindAddress -s -u XXXXXXXX
34723486
```
34733487
Additional parameters:
34743488
- `-s` - skip get URL
@@ -4257,12 +4271,13 @@ Note: Provide your UPRN. You can find it using [FindMyAddress](https://www.findm
42574271

42584272
### Wirral
42594273
```commandline
4260-
python collect_data.py WirralCouncil https://www.wirral.gov.uk -u XXXXXXXX
4274+
python collect_data.py WirralCouncil https://www.wirral.gov.uk -p "XXXX XXX" -w http://HOST:PORT/
42614275
```
42624276
Additional parameters:
4263-
- `-u` - UPRN
4277+
- `-p` - postcode
4278+
- `-w` - remote Selenium web driver URL (required for Home Assistant)
42644279

4265-
Note: In the `uprn` field, enter your street name and suburb separated by a comma (e.g., 'Vernon Avenue,Seacombe').
4280+
Note: Pass your postcode and house number.
42664281

42674282
---
42684283

0 commit comments

Comments
 (0)