Skip to content

Commit

Permalink
Merge pull request #838 from eugeneniemand/basildon-council
Browse files Browse the repository at this point in the history
  • Loading branch information
robbrad authored Oct 7, 2024
2 parents ef7cd71 + 425aeda commit 05ffb81
Show file tree
Hide file tree
Showing 2 changed files with 88 additions and 1 deletion.
8 changes: 7 additions & 1 deletion uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@
"wiki_name": "Barnsley Metropolitan Borough Council",
"wiki_note": "To get the UPRN, you will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search)."
},
"BasingstokeCouncil": {
"BasildonCouncil": {
"skip_get_url": true,
"uprn": "10013350430",
"url": "https://basildonportal.azurewebsites.net/api/getPropertyRefuseInformation",
"wiki_name": "Basildon Council"
},
"BasingstokeCouncil": {
"skip_get_url": true,
"uprn": "100060220926",
"url": "https://www.basingstoke.gov.uk/bincollection",
Expand Down
81 changes: 81 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/BasildonCouncil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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:
url_base = "https://basildonportal.azurewebsites.net/api/getPropertyRefuseInformation"

uprn = kwargs.get("uprn")
# Check the UPRN is valid
check_uprn(uprn)

payload = {
# Add your payload details here (replace this with the actual payload structure if required)
"uprn": uprn
}

# Headers for the request
headers = {
"Content-Type": "application/json"
}

response = requests.post(url_base, data=json.dumps(payload), headers=headers)

# Ensure the request was successful
if response.status_code == 200:
data = response.json()

# Initialize an empty list to store the bin collection details

bins = []

# Function to add collection details to bins list
def add_collection(service_name, collection_data):
bins.append({
"type": service_name,
"collectionDate": collection_data.get("current_collection_date")
})

# Extract refuse information
available_services = data["refuse"]["available_services"]

for service_name, service_data in available_services.items():
# Append the service name and current collection date to the "bins" list
match service_data["container"]:
case "Green Wheelie Bin":
subscription_status = service_data["subscription"]["active"] if service_data["subscription"] else False
type_descr = f"Green Wheelie Bin ({"Active" if subscription_status else "Expired"})"
case "N/A":
type_descr = service_data["name"]
case _:
type_descr = service_data["container"]


date_str = service_data.get("current_collection_date")
# Parse the date string into a datetime object
date_obj = datetime.strptime(date_str, "%Y-%m-%d")

# Convert the datetime object to the desired format
formatted_date = date_obj.strftime(date_format)

bins.append({
"type": type_descr, # Use service name from the data
"collectionDate": formatted_date
})

else:
print(f"Failed to fetch data. Status code: {response.status_code}")

data = {
"bins": bins
}

return data

0 comments on commit 05ffb81

Please sign in to comment.