Skip to content

Commit

Permalink
feat: Adding Wandsworth Council
Browse files Browse the repository at this point in the history
  • Loading branch information
m26dvd committed Dec 13, 2024
1 parent 8e70e6a commit 89d9366
Show file tree
Hide file tree
Showing 3 changed files with 93 additions and 0 deletions.
7 changes: 7 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -1897,6 +1897,13 @@
"wiki_name": "Waltham Forest",
"wiki_note": "Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN."
},
"WandsworthCouncil": {
"url": "https://www.wandsworth.gov.uk",
"wiki_command_url_override": "https://www.wandsworth.gov.uk",
"uprn": "100022684035",
"wiki_name": "Wandsworth Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"WarringtonBoroughCouncil": {
"url": "https://www.warrington.gov.uk",
"wiki_command_url_override": "https://www.warrington.gov.uk",
Expand Down
74 changes: 74 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/WandsworthCouncil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import requests
from bs4 import BeautifulSoup

from uk_bin_collection.uk_bin_collection.common import *
from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass


# import the wonderful Beautiful Soup and the URL grabber
class CouncilClass(AbstractGetBinDataClass):
"""
Concrete classes have to implement all abstract operations of the
base class. They can also override some operations with a default
implementation.
"""

def parse_data(self, page: str, **kwargs) -> dict:

user_uprn = kwargs.get("uprn")
check_uprn(user_uprn)
bindata = {"bins": []}

URI = f"https://www.wandsworth.gov.uk/my-property/?UPRN={user_uprn}"

# Make the GET request
response = requests.get(URI)

soup = BeautifulSoup(response.content, features="html.parser")
soup.prettify()

# Find all collection types
collection_types = soup.find_all("h4", class_="collection-heading")

# Iterate over each collection type
for collection_type in collection_types:
bin_types = collection_type.text.strip().split("/")
collections = collection_type.find_next_sibling("div", class_="collections")

# Extract next and previous collections
next_collection = collections.find_all("div", class_="collection")

# Parse each collection
for collection in next_collection:
# Extract the collection type (Next or Previous)
strong_tag = collection.find("strong")
collection_type = (
strong_tag.text.strip(":") if strong_tag else "Unknown"
)

# Extract the date
date_text = (
strong_tag.next_sibling.strip()
if strong_tag and strong_tag.next_sibling
else "No date found"
)

if date_text == "No date found":
continue

for bin_type in bin_types:
# Append to the schedule
dict_data = {
"type": bin_type,
"collectionDate": datetime.strptime(
date_text,
"%A %d %B %Y",
).strftime(date_format),
}
bindata["bins"].append(dict_data)

bindata["bins"].sort(
key=lambda x: datetime.strptime(x.get("collectionDate"), date_format)
)

return bindata
12 changes: 12 additions & 0 deletions wiki/Councils.md
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,7 @@ This document is still a work in progress, don't worry if your council isn't lis
- [Wakefield City Council](#wakefield-city-council)
- [Walsall Council](#walsall-council)
- [Waltham Forest](#waltham-forest)
- [Wandsworth Council](#wandsworth-council)
- [Warrington Borough Council](#warrington-borough-council)
- [Warwick District Council](#warwick-district-council)
- [Watford Borough Council](#watford-borough-council)
Expand Down Expand Up @@ -3237,6 +3238,17 @@ Note: Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your U

---

### Wandsworth Council
```commandline
python collect_data.py WandsworthCouncil https://www.wandsworth.gov.uk -u XXXXXXXX
```
Additional parameters:
- `-u` - UPRN

Note: You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN.

---

### Warrington Borough Council
```commandline
python collect_data.py WarringtonBoroughCouncil https://www.warrington.gov.uk -u XXXXXXXX
Expand Down

0 comments on commit 89d9366

Please sign in to comment.