diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index 55ad1cb12d..f7d7746bd3 100755 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -440,7 +440,7 @@ "uprn": "100110734613", "url": "https://www.copeland.gov.uk", "wiki_name": "Copeland Borough Council", - "wiki_note": "Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN." + "wiki_note": "*****This has now been replaced by Cumberland Council****" }, "CornwallCouncil": { "skip_get_url": true, @@ -486,6 +486,12 @@ "wiki_name": "Croydon Council", "wiki_note": "Pass the house number and postcode in their respective parameters." }, + "CumberlandCouncil": { + "uprn": "100110734613", + "url": "https://waste.cumberland.gov.uk", + "wiki_name": "Cumberland Borough Council", + "wiki_note": "Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN." + }, "CumberlandAllerdaleCouncil": { "house_number": "2", "postcode": "CA13 0DE", diff --git a/uk_bin_collection/uk_bin_collection/councils/CumberlandCouncil.py b/uk_bin_collection/uk_bin_collection/councils/CumberlandCouncil.py new file mode 100644 index 0000000000..90bdc6c2b8 --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/CumberlandCouncil.py @@ -0,0 +1,96 @@ +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 = "https://waste.cumberland.gov.uk/renderform?t=25&k=E43CEB1FB59F859833EF2D52B16F3F4EBE1CAB6A" + + s = requests.Session() + + # Make the GET request + response = s.get(URI) + + # Make a BS4 object + soup = BeautifulSoup(response.content, features="html.parser") + + # print(soup) + + token = (soup.find("input", {"name": "__RequestVerificationToken"})).get( + "value" + ) + + formguid = (soup.find("input", {"name": "FormGuid"})).get("value") + + # print(token) + # print(formguid) + + headers = { + "Content-Type": "application/x-www-form-urlencoded", + "Origin": "https://waste.cumberland.gov.uk", + "Referer": "https://waste.cumberland.gov.uk/renderform?t=25&k=E43CEB1FB59F859833EF2D52B16F3F4EBE1CAB6A", + "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/112.0.0.0 Safari/537.36 OPR/98.0.0.0", + "X-Requested-With": "XMLHttpRequest", + } + + payload = { + "__RequestVerificationToken": token, + "FormGuid": formguid, + "ObjectTemplateID": "25", + "Trigger": "submit", + "CurrentSectionID": "33", + "TriggerCtl": "", + "FF265": f"U{user_uprn}", + "FF265lbltxt": "Please select your address", + } + + # print(payload) + + response = s.post( + "https://waste.cumberland.gov.uk/renderform/Form", + headers=headers, + data=payload, + ) + + soup = BeautifulSoup(response.content, features="html.parser") + for row in soup.find_all("div", class_="resirow"): + # Extract the type of collection (e.g., Recycling, Refuse) + collection_type_div = row.find("div", class_="col") + collection_type = ( + collection_type_div.get("class")[1] + if collection_type_div + else "Unknown" + ) + + # Extract the collection date + date_div = row.find("div", style="width:360px;") + collection_date = date_div.text.strip() if date_div else "Unknown" + + dict_data = { + "type": collection_type, + "collectionDate": datetime.strptime( + collection_date, "%A %d %B %Y" + ).strftime(date_format), + } + bindata["bins"].append(dict_data) + + bindata["bins"].sort( + key=lambda x: datetime.strptime(x.get("collectionDate"), "%d/%m/%Y") + ) + + return bindata diff --git a/wiki/Councils.md b/wiki/Councils.md index d8488235d6..508a83987c 100644 --- a/wiki/Councils.md +++ b/wiki/Councils.md @@ -72,6 +72,7 @@ This document is still a work in progress, don't worry if your council isn't lis - [Cotswold District Council](#cotswold-district-council) - [Crawley Borough Council](#crawley-borough-council) - [Croydon Council](#croydon-council) +- [Cumberland Borough Council](#cumberland-borough-council) - [Cumberland Council - Allerdale District](#cumberland-council---allerdale-district) - [Dacorum Borough Council](#dacorum-borough-council) - [Dartford Borough Council](#dartford-borough-council) @@ -984,7 +985,7 @@ python collect_data.py CopelandBoroughCouncil https://www.copeland.gov.uk -u XXX Additional parameters: - `-u` - UPRN -Note: Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN. +Note: *****This has now been replaced by Cumberland Council**** --- @@ -1049,6 +1050,17 @@ Note: Pass the house number and postcode in their respective parameters. --- +### Cumberland Borough Council +```commandline +python collect_data.py CumberlandCouncil https://waste.cumberland.gov.uk -u XXXXXXXX +``` +Additional parameters: +- `-u` - UPRN + +Note: Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN. + +--- + ### Cumberland Council - Allerdale District ```commandline python collect_data.py CumberlandAllerdaleCouncil https://www.allerdale.gov.uk -p "XXXX XXX" -n XX