Skip to content

Commit

Permalink
feat: Adding Cumberland Council
Browse files Browse the repository at this point in the history
fix: #1110
  • Loading branch information
m26dvd committed Jan 5, 2025
1 parent 0e76f53 commit 51e2323
Show file tree
Hide file tree
Showing 3 changed files with 116 additions and 2 deletions.
8 changes: 7 additions & 1 deletion uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
96 changes: 96 additions & 0 deletions uk_bin_collection/uk_bin_collection/councils/CumberlandCouncil.py
Original file line number Diff line number Diff line change
@@ -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
14 changes: 13 additions & 1 deletion wiki/Councils.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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****

---

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 51e2323

Please sign in to comment.