Skip to content

Commit

Permalink
feat: Adding Redditch Borough Council
Browse files Browse the repository at this point in the history
fix: #1068
  • Loading branch information
m26dvd committed Dec 22, 2024
1 parent 5c7c86e commit 419d9e6
Show file tree
Hide file tree
Showing 3 changed files with 92 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 @@ -1405,6 +1405,13 @@
"wiki_name": "Reading Borough Council",
"wiki_note": "Replace XXXXXXXX with your property's UPRN."
},
"RedditchBoroughCouncil": {
"url": "https://redditchbc.gov.uk",
"wiki_command_url_override": "https://redditchbc.gov.uk",
"uprn": "10094557691",
"wiki_name": "Redditch Borough Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"ReigateAndBansteadBoroughCouncil": {
"skip_get_url": true,
"uprn": "68134867",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
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 = "https://bincollections.redditchbc.gov.uk/BinCollections/Details"

data = {"UPRN": user_uprn}

# Make the GET request
response = requests.post(URI, data=data)

# Parse the HTML
soup = BeautifulSoup(response.content, "html.parser")

# Find all collection containers
collection_containers = soup.find_all("div", class_="collection-container")

# Parse each collection container
for container in collection_containers:
# Extract bin type (from heading or image alt attribute)
bin_type = container.find("img")["alt"]

# Extract the next collection date (from the caption paragraph)
next_collection = (
container.find("p", class_="caption")
.text.replace("Next collection ", "")
.strip()
)

# Extract additional future collection dates (from the list items)
future_dates = [li.text.strip() for li in container.find_all("li")]

dict_data = {
"type": bin_type,
"collectionDate": datetime.strptime(
next_collection,
"%A, %d %B %Y",
).strftime("%d/%m/%Y"),
}
bindata["bins"].append(dict_data)

for date in future_dates: # Add to the schedule
dict_data = {
"type": bin_type,
"collectionDate": datetime.strptime(
date,
"%A, %d %B %Y",
).strftime("%d/%m/%Y"),
}
bindata["bins"].append(dict_data)

bindata["bins"].sort(
key=lambda x: datetime.strptime(x.get("collectionDate"), "%d/%m/%Y")
)

return bindata
12 changes: 12 additions & 0 deletions wiki/Councils.md
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ This document is still a work in progress, don't worry if your council isn't lis
- [Powys Council](#powys-council)
- [Preston City Council](#preston-city-council)
- [Reading Borough Council](#reading-borough-council)
- [Redditch Borough Council](#redditch-borough-council)
- [Reigate and Banstead Borough Council](#reigate-and-banstead-borough-council)
- [Renfrewshire Council](#renfrewshire-council)
- [Rhondda Cynon Taff Council](#rhondda-cynon-taff-council)
Expand Down Expand Up @@ -2472,6 +2473,17 @@ Note: Replace XXXXXXXX with your property's UPRN.

---

### Redditch Borough Council
```commandline
python collect_data.py RedditchBoroughCouncil https://redditchbc.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.

---

### Reigate and Banstead Borough Council
```commandline
python collect_data.py ReigateAndBansteadBoroughCouncil https://www.reigate-banstead.gov.uk/ -s -u XXXXXXXX -w http://HOST:PORT/
Expand Down

0 comments on commit 419d9e6

Please sign in to comment.