Skip to content

Commit

Permalink
feat: Adding Braintree District Council
Browse files Browse the repository at this point in the history
fix: #699
  • Loading branch information
m26dvd committed Nov 17, 2024
1 parent 04e5495 commit b6237c3
Show file tree
Hide file tree
Showing 3 changed files with 92 additions and 0 deletions.
8 changes: 8 additions & 0 deletions uk_bin_collection/tests/input.json
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,14 @@
"wiki_name": "Bradford MDC",
"wiki_note": "To get the UPRN, you will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search). Postcode isn't parsed by this script, but you can pass it in double quotes."
},
"BraintreeDistrictCouncil": {
"postcode": "CO5 9BD",
"skip_get_url": true,
"uprn": "10006930172",
"url": "https://www.braintree.gov.uk/",
"wiki_name": "Braintree District Council",
"wiki_note": "Provide your UPRN and postcode. Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN."
},
"BrecklandCouncil": {
"url": "https://www.breckland.gov.uk",
"wiki_command_url_override": "https://www.breckland.gov.uk",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import time

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_postcode = kwargs.get("postcode")
user_uprn = kwargs.get("uprn")
check_postcode(user_postcode)
check_uprn(user_uprn)
bindata = {"bins": []}

URI = "https://www.braintree.gov.uk/xfp/form/554"

response = requests.get(URI)
soup = BeautifulSoup(response.content, "html.parser")
token = (soup.find("input", {"name": "__token"})).get("value")

headers = {
"Content-Type": "application/x-www-form-urlencoded",
"User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/130.0.0.0 Safari/537.36",
"Referer": "https://www.braintree.gov.uk/xfp/form/554",
}

form_data = {
"__token": token,
"page": "5730",
"locale": "en_GB",
"qe15dda0155d237d1ea161004d1839e3369ed4831_0_0": user_postcode,
"qe15dda0155d237d1ea161004d1839e3369ed4831_1_0": user_uprn,
"next": "Next",
}
collection_lookup = requests.post(URI, data=form_data, headers=headers)
collection_lookup.raise_for_status()
for results in BeautifulSoup(collection_lookup.text, "html.parser").find_all(
"div", class_="date_display"
):
collection_info = results.text.strip().split("\n")
collection_type = collection_info[0].strip()

# Skip if no collection date is found
if len(collection_info) < 2:
continue

collection_date = collection_info[1].strip()

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

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

return bindata
14 changes: 14 additions & 0 deletions wiki/Councils.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ This document is still a work in progress, don't worry if your council isn't lis
- [Bolton Council](#bolton-council)
- [Bracknell Forest Council](#bracknell-forest-council)
- [Bradford MDC](#bradford-mdc)
- [Braintree District Council](#braintree-district-council)
- [Breckland Council](#breckland-council)
- [Brighton and Hove City Council](#brighton-and-hove-city-council)
- [Bristol City Council](#bristol-city-council)
Expand Down Expand Up @@ -608,6 +609,19 @@ Note: To get the UPRN, you will need to use [FindMyAddress](https://www.findmyad

---

### Braintree District Council
```commandline
python collect_data.py BraintreeDistrictCouncil https://www.braintree.gov.uk/ -s -u XXXXXXXX -p "XXXX XXX"
```
Additional parameters:
- `-s` - skip get URL
- `-u` - UPRN
- `-p` - postcode

Note: Provide your UPRN and postcode. Use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find your UPRN.

---

### Breckland Council
```commandline
python collect_data.py BrecklandCouncil https://www.breckland.gov.uk -u XXXXXXXX
Expand Down

0 comments on commit b6237c3

Please sign in to comment.