Skip to content

Commit

Permalink
feat: Adding Oadby And Wigston Borough Council
Browse files Browse the repository at this point in the history
fix: #929
  • Loading branch information
m26dvd committed Jan 7, 2025
1 parent a5037e0 commit 2ce01ed
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 0 deletions.
6 changes: 6 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -1373,6 +1373,12 @@
"house_number": "Newdigate Road",
"wiki_note": "Pass the name of the street ONLY in the house number parameter, wrapped in double quotes. Street name must match exactly as it appears on the council's website."
},
"OadbyAndWigstonBoroughCouncil": {
"url": "https://my.oadby-wigston.gov.uk",
"uprn": "10010149102",
"wiki_name": "Oadby & Wigston Borough Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"OldhamCouncil": {
"url": "https://portal.oldham.gov.uk/bincollectiondates/details?uprn=422000033556",
"wiki_name": "Oldham Council",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
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://my.oadby-wigston.gov.uk/location?put=ow{user_uprn}&rememberme=0&redirect=%2F"

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

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

# Find the collection list
collection_list = soup.find("ul", class_="refuse")

current_year = datetime.now().year
next_year = current_year + 1

# Loop through each collection item
for li in collection_list.find_all("li"):
date_text = li.find("strong", class_="date").text.strip()
bin_type = li.find("a").text # Get the class for bin type

# Parse the date
if date_text == "Today":
collection_date = datetime.now()
else:
try:
collection_date = datetime.strptime(date_text, "%A %d %b")
except:
continue

if (datetime.now().month == 12) and (collection_date.month == 1):
collection_date = collection_date.replace(year=next_year)
else:
collection_date = collection_date.replace(year=current_year)

dict_data = {
"type": bin_type,
"collectionDate": collection_date.strftime(date_format),
}
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 @@ -189,6 +189,7 @@ This document is still a work in progress, don't worry if your council isn't lis
- [Northumberland Council](#northumberland-council)
- [Nottingham City Council](#nottingham-city-council)
- [Nuneaton and Bedworth Borough Council](#nuneaton-and-bedworth-borough-council)
- [Oadby & Wigston Borough Council](#oadby-&-wigston-borough-council)
- [Oldham Council](#oldham-council)
- [Oxford City Council](#oxford-city-council)
- [Perth and Kinross Council](#perth-and-kinross-council)
Expand Down Expand Up @@ -2454,6 +2455,17 @@ Note: Pass the name of the street ONLY in the house number parameter, wrapped in

---

### Oadby & Wigston Borough Council
```commandline
python collect_data.py OadbyAndWigstonBoroughCouncil https://my.oadby-wigston.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.

---

### Oldham Council
```commandline
python collect_data.py OldhamCouncil https://portal.oldham.gov.uk/bincollectiondates/details?uprn=422000033556
Expand Down

0 comments on commit 2ce01ed

Please sign in to comment.