From 04e54955dae79e4bfc1cdf27298fe91a1bfbf5c2 Mon Sep 17 00:00:00 2001 From: m26dvd <31007572+m26dvd@users.noreply.github.com> Date: Sun, 17 Nov 2024 02:33:06 +0000 Subject: [PATCH] feat: Adding Burnley Borough Council fix: #1015 --- uk_bin_collection/tests/input.json | 6 ++ .../councils/BurnleyBoroughCouncil.py | 88 +++++++++++++++++++ wiki/Councils.md | 12 +++ 3 files changed, 106 insertions(+) create mode 100644 uk_bin_collection/uk_bin_collection/councils/BurnleyBoroughCouncil.py diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index 589083f22b..9ec68acafd 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -282,6 +282,12 @@ "wiki_name": "Buckinghamshire Council (Chiltern, South Bucks, Wycombe)", "wiki_note": "Pass the house name/number and postcode in their respective arguments, both wrapped in quotes." }, + "BurnleyBoroughCouncil": { + "uprn": "100010347165", + "url": "https://www.burnley.gov.uk", + "wiki_name": "Burnley Borough Council", + "wiki_note": "Pass the UPRN. You can find it using [FindMyAddress](https://www.findmyaddress.co.uk/search)." + }, "BuryCouncil": { "house_number": "3", "postcode": "M26 3XY", diff --git a/uk_bin_collection/uk_bin_collection/councils/BurnleyBoroughCouncil.py b/uk_bin_collection/uk_bin_collection/councils/BurnleyBoroughCouncil.py new file mode 100644 index 0000000000..97283ce09b --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/BurnleyBoroughCouncil.py @@ -0,0 +1,88 @@ +import time + +import requests + +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": []} + + SESSION_URL = "https://your.burnley.gov.uk/authapi/isauthenticated?uri=https%253A%252F%252Fyour.burnley.gov.uk%252Fen%252FAchieveForms%252F%253Fform_uri%253Dsandbox-publish%253A%252F%252FAF-Process-b41dcd03-9a98-41be-93ba-6c172ba9f80c%252FAF-Stage-edb97458-fc4d-4316-b6e0-85598ec7fce8%252Fdefinition.json%2526redirectlink%253D%25252Fen%2526cancelRedirectLink%253D%25252Fen%2526consentMessage%253Dyes&hostname=your.burnley.gov.uk&withCredentials=true" + + API_URL = "https://your.burnley.gov.uk/apibroker/runLookup" + + headers = { + "Content-Type": "application/json", + "Accept": "application/json", + "User-Agent": "Mozilla/5.0", + "X-Requested-With": "XMLHttpRequest", + "Referer": "https://your.burnley.gov.uk/fillform/?iframe_id=fillform-frame-1&db_id=", + } + s = requests.session() + r = s.get(SESSION_URL) + r.raise_for_status() + session_data = r.json() + sid = session_data["auth-session"] + + data = { + "formValues": { + "Section 1": { + "case_uprn1": { + "value": user_uprn, + } + }, + }, + } + + params = { + "id": "607fe757df87c", + "repeat_against": "", + "noRetry": "false", + "getOnlyTokens": "undefined", + "log_id": "", + "app_name": "AF-Renderer::Self", + # unix_timestamp + "_": str(int(time.time() * 1000)), + "sid": sid, + } + + r = s.post(API_URL, json=data, headers=headers, params=params) + r.raise_for_status() + + data = r.json() + rows_data = data["integration"]["transformed"]["rows_data"] + if not isinstance(rows_data, dict): + raise ValueError("Invalid data returned from API") + + current_year = (datetime.now()).year + for key, value in rows_data.items(): + bin_type = value["display"].split(" - ")[0] + collection_date = datetime.strptime( + value["display"].split(" - ")[1], "%A %d %B" + ) + + if collection_date.month == 1: + collection_date = collection_date.replace(year=current_year + 1) + else: + collection_date = collection_date.replace(year=current_year) + + dict_data = { + "type": bin_type, + "collectionDate": collection_date.strftime(date_format), + } + bindata["bins"].append(dict_data) + + return bindata diff --git a/wiki/Councils.md b/wiki/Councils.md index eba95f6a31..18677474dd 100644 --- a/wiki/Councils.md +++ b/wiki/Councils.md @@ -46,6 +46,7 @@ This document is still a work in progress, don't worry if your council isn't lis - [Broxbourne Council](#broxbourne-council) - [Broxtowe Borough Council](#broxtowe-borough-council) - [Buckinghamshire Council (Chiltern, South Bucks, Wycombe)](#buckinghamshire-council-(chiltern,-south-bucks,-wycombe)) +- [Burnley Borough Council](#burnley-borough-council) - [Bury Council](#bury-council) - [Calderdale Council](#calderdale-council) - [Cannock Chase District Council](#cannock-chase-district-council) @@ -707,6 +708,17 @@ Note: Pass the house name/number and postcode in their respective arguments, bot --- +### Burnley Borough Council +```commandline +python collect_data.py BurnleyBoroughCouncil https://www.burnley.gov.uk -u XXXXXXXX +``` +Additional parameters: +- `-u` - UPRN + +Note: Pass the UPRN. You can find it using [FindMyAddress](https://www.findmyaddress.co.uk/search). + +--- + ### Bury Council ```commandline python collect_data.py BuryCouncil https://www.bury.gov.uk/waste-and-recycling/bin-collection-days-and-alerts -s -p "XXXX XXX" -n XX