diff --git a/uk_bin_collection/tests/features/validate_council_outputs.feature b/uk_bin_collection/tests/features/validate_council_outputs.feature index c32b0885a9..a939a20a1f 100644 --- a/uk_bin_collection/tests/features/validate_council_outputs.feature +++ b/uk_bin_collection/tests/features/validate_council_outputs.feature @@ -88,6 +88,7 @@ Feature: Test each council output matches expected results | SalfordCityCouncil | None | None | | SevenoaksDistrictCouncil | http://selenium:4444 | local | | SheffieldCityCouncil | None | None | + | ShropshireCouncil | None | None | | SomersetCouncil | None | None | | SouthAyrshireCouncil | None | None | | SouthCambridgeshireCouncil | None | None | diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index 9f3d88c023..711c43423e 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -552,6 +552,12 @@ "wiki_name": "Sheffield City Council", "wiki_note": "Follow the instructions [here](https://wasteservices.sheffield.gov.uk/) until you get the \"Your bin collection dates and services\" page then copy the URL and replace the URL in the command." }, + "ShropshireCouncil": { + "url": "https://bins.shropshire.gov.uk/property/100070034731", + "wiki_command_url_override": "https://bins.shropshire.gov.uk/property/XXXXXXXXXXX", + "wiki_name": "Shropshire Council", + "wiki_note": "Follow the instructions [here](https://bins.shropshire.gov.uk/) until you get the page showing your bin collection dates then copy the URL and replace the URL in the command." + }, "SomersetCouncil": { "postcode": "TA6 4AA", "skip_get_url": true, diff --git a/uk_bin_collection/uk_bin_collection/councils/ShropshireCouncil.py b/uk_bin_collection/uk_bin_collection/councils/ShropshireCouncil.py new file mode 100644 index 0000000000..56367f7730 --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/ShropshireCouncil.py @@ -0,0 +1,38 @@ +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 + + +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: + # Make a BS4 object + soup = BeautifulSoup(page.text, features="html.parser") + soup.prettify() + + # Form a JSON wrapper + data = {"bins": []} + + # Find section with bins in + sections = soup.find("div", {"class": "container results-table-wrapper"}).find("tbody").find_all("tr") + + # For each bin section, get the text and the list elements + for item in sections: + words = item.find_next("a").text.split()[1:2] + bin_type = ' '.join(words).capitalize() + date = item.find("td", {"class": "next-service"}).find_next("span").next_sibling.strip() + next_collection = datetime.strptime(date, "%d/%m/%Y") + dict_data = { + "type": bin_type, + "collectionDate": next_collection.strftime(date_format), + } + data["bins"].append(dict_data) + + return data +