diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index ce5bc0a29f..fa1afb7fad 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -1929,6 +1929,13 @@ "wiki_name": "Worcester City Council", "wiki_note": "Provide your UPRN. You can find it using [FindMyAddress](https://www.findmyaddress.co.uk/search)." }, + "WolverhamptonCityCouncil": { + "uprn": "100071205205", + "postcode": "WV3 9NZ", + "url": "https://www.wolverhampton.gov.uk", + "wiki_name": "Wolverhampton City Council", + "wiki_note": "Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN." + }, "WorcesterCityCouncil": { "url": "https://www.Worcester.gov.uk", "wiki_command_url_override": "https://www.Worcester.gov.uk", diff --git a/uk_bin_collection/uk_bin_collection/councils/WolverhamptonCityCouncil.py b/uk_bin_collection/uk_bin_collection/councils/WolverhamptonCityCouncil.py new file mode 100644 index 0000000000..15041d9ca3 --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/WolverhamptonCityCouncil.py @@ -0,0 +1,57 @@ +import time + +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") + user_postcode = kwargs.get("postcode") + check_uprn(user_uprn) + check_postcode(user_postcode) + bindata = {"bins": []} + + user_postcode = user_postcode.replace(" ", "%20") + + URI = f"https://www.wolverhampton.gov.uk/find-my-nearest/{user_postcode}/{user_uprn}" + + # Make the GET request + response = requests.get(URI) + + soup = BeautifulSoup(response.content, "html.parser") + + jumbotron = soup.find("div", {"class": "jumbotron jumbotron-fluid"}) + + # Find all bin entries in the row + for bin_div in jumbotron.select("div.col-md-4"): + service_name = bin_div.h3.text.strip() + next_date = bin_div.find( + "h4", text=lambda x: x and "Next date" in x + ).text.split(": ")[1] + + dict_data = { + "type": service_name, + "collectionDate": datetime.strptime( + next_date, + "%B %d, %Y", + ).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 af69f6046f..3f6919219c 100644 --- a/wiki/Councils.md +++ b/wiki/Councils.md @@ -256,6 +256,7 @@ This document is still a work in progress, don't worry if your council isn't lis - [Woking Borough Council / Joint Waste Solutions](#woking-borough-council-/-joint-waste-solutions) - [Wokingham Borough Council](#wokingham-borough-council) - [Worcester City Council](#worcester-city-council) +- [Wolverhampton City Council](#wolverhampton-city-council) - [Wychavon District Council](#wychavon-district-council) - [Wyre Council](#wyre-council) - [York Council](#york-council) @@ -3236,6 +3237,18 @@ Note: You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/searc --- +### Wolverhampton City Council +```commandline +python collect_data.py WolverhamptonCityCouncil https://www.wolverhampton.gov.uk -u XXXXXXXX -p "XXXX XXX" +``` +Additional parameters: +- `-u` - UPRN +- `-p` - postcode + +Note: Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN. + +--- + ### Wychavon District Council ```commandline python collect_data.py WychavonDistrictCouncil https://selfservice.wychavon.gov.uk/wdcroundlookup/wdc_search.jsp -s -u XXXXXXXX -p "XXXX XXX" -w http://HOST:PORT/