Skip to content

Commit

Permalink
Merge pull request #478 from dandantheitman/new-councils
Browse files Browse the repository at this point in the history
feat: Add Shropshire Council
  • Loading branch information
dp247 authored Dec 12, 2023
2 parents 6eefa66 + 5e88d48 commit fc15951
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 0 deletions.
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

0 comments on commit fc15951

Please sign in to comment.