Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Shropshire Council #478

Merged
merged 1 commit into from
Dec 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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 |
Expand Down
6 changes: 6 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
38 changes: 38 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/ShropshireCouncil.py
Original file line number Diff line number Diff line change
@@ -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

Loading