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 Herefordshire Council (closes: #1023) #1198

Merged
merged 3 commits into from
Jan 29, 2025
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
6 changes: 6 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -887,6 +887,12 @@
"wiki_name": "Hartlepool Borough Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN."
},
"HerefordshireCouncil": {
"url": "https://www.herefordshire.gov.uk/rubbish-recycling/check-bin-collection-day?blpu_uprn=10096232662",
"wiki_command_url_override": "https://www.herefordshire.gov.uk/rubbish-recycling/check-bin-collection-day?blpu_uprn=XXXXXXXXXXXX",
"wiki_name": "Herefordshire Council",
"wiki_note": "Replace 'XXXXXXXXXX' with your property's UPRN. You can find it using [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"HertsmereBoroughCouncil": {
"house_number": "1",
"postcode": "WD7 9HZ",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import logging

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:
# Make a BS4 object
soup = BeautifulSoup(page.text, features="html.parser")
soup.prettify()

data = {"bins": []}

checkValid = soup.find("p", id="selectedAddressResult")
if checkValid is None:
raise ValueError("Address/UPRN not found")

collections = soup.find("div", id="wasteCollectionDates")

for bins in collections.select('div[class*="hc-island"]'):
bin_type = bins.h4.get_text(strip=True)

# Last div.hc-island is the calendar link, skip it
if bin_type == "Calendar":
continue

# Next collection date is in a span under the second p.hc-no-margin of the div.
bin_collection = re.search(
r"(.*) \(.*\)", bins.select("div > p > span")[0].get_text(strip=True)
).group(1)
if bin_collection:
logging.info(
f"Bin type: {bin_type} - Collection date: {bin_collection}"
)
dict_data = {
"type": bin_type,
"collectionDate": datetime.strptime(
bin_collection, "%A %d %B %Y"
).strftime(date_format),
}
data["bins"].append(dict_data)

return data
Loading