Skip to content

Commit

Permalink
feat: Adding Flintshire County Council
Browse files Browse the repository at this point in the history
fix: #750
  • Loading branch information
m26dvd authored and robbrad committed Nov 6, 2024
1 parent 8c6c3ee commit 546f04f
Show file tree
Hide file tree
Showing 2 changed files with 67 additions and 0 deletions.
7 changes: 7 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -484,6 +484,13 @@
"url": "https://www.fenland.gov.uk/article/13114/",
"wiki_name": "Fenland District Council"
},
"FlintshireCountyCouncil": {
"url": "https://digital.flintshire.gov.uk",
"wiki_command_url_override": "https://digital.flintshire.gov.uk",
"uprn": "100100213710",
"wiki_name": "Flintshire County Council",
"wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN."
},
"ForestOfDeanDistrictCouncil": {
"house_number": "ELMOGAL, PARKEND ROAD, BREAM, LYDNEY",
"postcode": "GL15 6JT",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
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")
check_uprn(user_uprn)
bindata = {"bins": []}

URI = f"https://digital.flintshire.gov.uk/FCC_BinDay/Home/Details2/{user_uprn}"

# Make the GET request
response = requests.get(URI)

# Parse the HTML content
soup = BeautifulSoup(response.content, "html.parser")

# Adjust these tags and classes based on actual structure
# Example for finding collection dates and types
bin_collections = soup.find_all(
"div", class_="col-md-12 col-lg-12 col-sm-12 col-xs-12"
) # Replace with actual class name

# Extracting and printing the schedule data
schedule = []
for collection in bin_collections:
dates = collection.find_all("div", class_="col-lg-2 col-md-2 col-sm-2")
bin_type = collection.find("div", class_="col-lg-3 col-md-3 col-sm-3")

if dates[0].text.strip() == "Date of Collection":
continue

bin_types = bin_type.text.strip().split(" / ")
date = dates[0].text.strip()

# Loop through the dates for each collection type
for bin_type in bin_types:

dict_data = {
"type": bin_type,
"collectionDate": date,
}
bindata["bins"].append(dict_data)

bindata["bins"].sort(
key=lambda x: datetime.strptime(x.get("collectionDate"), "%d/%m/%Y")
)
return bindata

0 comments on commit 546f04f

Please sign in to comment.