From 3c40ef209310a4b57c0b319c48bc0cc24ca9c4e7 Mon Sep 17 00:00:00 2001 From: m26dvd <31007572+m26dvd@users.noreply.github.com> Date: Thu, 31 Oct 2024 22:03:59 +0000 Subject: [PATCH] feat: Adding Breckland Council fix: #656 --- uk_bin_collection/tests/input.json | 7 +++ .../councils/BrecklandCouncil.py | 55 +++++++++++++++++++ wiki/Councils.md | 12 ++++ 3 files changed, 74 insertions(+) create mode 100644 uk_bin_collection/uk_bin_collection/councils/BrecklandCouncil.py diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index a47a767641..af672b4173 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -159,6 +159,13 @@ "wiki_name": "Bradford MDC", "wiki_note": "To get the UPRN, you will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search). Post code isn't parsed by this script, but you can pass it in double quotes." }, + "BrecklandCouncil": { + "url": "https://www.breckland.gov.uk", + "wiki_command_url_override": "https://www.breckland.gov.uk", + "uprn": "100091495479", + "wiki_name": "Breckland Council", + "wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN." + }, "BrightonandHoveCityCouncil": { "house_number": "44 Carden Avenue, Brighton, BN1 8NE", "postcode": "BN1 8NE", diff --git a/uk_bin_collection/uk_bin_collection/councils/BrecklandCouncil.py b/uk_bin_collection/uk_bin_collection/councils/BrecklandCouncil.py new file mode 100644 index 0000000000..1ae477860d --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/BrecklandCouncil.py @@ -0,0 +1,55 @@ +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": []} + + URI = "https://www.breckland.gov.uk/apiserver/ajaxlibrary" + + data = { + "id": "1730410741649", + "jsonrpc": "2.0", + "method": "Breckland.Whitespace.JointWasteAPI.GetBinCollectionsByUprn", + "params": {"uprn": user_uprn, "environment": "live"}, + } + # Make the GET request + response = requests.post(URI, json=data) + + # Parse the JSON response + bin_collection = response.json() + + # Loop through each collection in bin_collection + for collection in bin_collection["result"]: + bin_type = collection.get("collectiontype") + collection_date = collection.get("nextcollection") + + dict_data = { + "type": bin_type, + "collectionDate": datetime.strptime( + collection_date, + "%d/%m/%Y %H:%M:%S", + ).strftime("%d/%m/%Y"), + } + 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 bc5a2547e0..28351eb1ea 100644 --- a/wiki/Councils.md +++ b/wiki/Councils.md @@ -32,6 +32,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) +- [Breckland Council](#breckland-council) - [Brighton and Hove City Council](#brighton-and-hove-city-council) - [Bristol City Council](#bristol-city-council) - [Bromley Borough Council](#bromley-borough-council) @@ -487,6 +488,17 @@ Note: To get the UPRN, you will need to use [FindMyAddress](https://www.findmyad --- +### Breckland Council +```commandline +python collect_data.py BrecklandCouncil https://www.breckland.gov.uk -u XXXXXXXX +``` +Additional parameters: +- `-u` - UPRN + +Note: You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN. + +--- + ### Brighton and Hove City Council ```commandline python collect_data.py BrightonandHoveCityCouncil https://cityclean.brighton-hove.gov.uk/link/collections -s -u XXXXXXXX -p "XXXX XXX" -n XX -w http://HOST:PORT/