diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index 970d6dcf4d..e22eb904fc 100755 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -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", diff --git a/uk_bin_collection/uk_bin_collection/councils/OadbyAndWigstonBoroughCouncil.py b/uk_bin_collection/uk_bin_collection/councils/OadbyAndWigstonBoroughCouncil.py new file mode 100644 index 0000000000..a3ef9d2986 --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/OadbyAndWigstonBoroughCouncil.py @@ -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 diff --git a/wiki/Councils.md b/wiki/Councils.md index 1f550ba1a7..494a9a08d7 100644 --- a/wiki/Councils.md +++ b/wiki/Councils.md @@ -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) @@ -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