From edf9b8ed520ba2063d583490696c0d0f7f0bacbb Mon Sep 17 00:00:00 2001 From: skelt0 <16990151+skelt0@users.noreply.github.com> Date: Tue, 12 Dec 2023 23:02:20 +0000 Subject: [PATCH] feat: Adding support for Reading Borough Council --- .../features/validate_council_outputs.feature | 1 + uk_bin_collection/tests/input.json | 9 ++++-- .../councils/ReadingBoroughCouncil.py | 29 +++++++++++++++++++ 3 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 uk_bin_collection/uk_bin_collection/councils/ReadingBoroughCouncil.py diff --git a/uk_bin_collection/tests/features/validate_council_outputs.feature b/uk_bin_collection/tests/features/validate_council_outputs.feature index a939a20a1f..395be011d1 100644 --- a/uk_bin_collection/tests/features/validate_council_outputs.feature +++ b/uk_bin_collection/tests/features/validate_council_outputs.feature @@ -79,6 +79,7 @@ Feature: Test each council output matches expected results | NorthumberlandCouncil | http://selenium:4444 | local | | NorthWestLeicestershire | http://selenium:4444 | local | | PrestonCityCouncil | http://selenium:4444 | local | + | ReadingBoroughCouncil | None | None | | ReigateAndBansteadBoroughCouncil | http://selenium:4444 | local | | RhonddaCynonTaffCouncil | None | None | | RochdaleCouncil | None | None | diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index 711c43423e..c44b7907c2 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -489,6 +489,12 @@ "web_driver": "http://selenium:4444", "wiki_name": "Preston City Council" }, + "ReadingBoroughCouncil": { + "url": "https://api.reading.gov.uk/api/collections/310056735", + "wiki_command_url_override": "https://api.reading.gov.uk/api/collections/XXXXXXXX", + "wiki_name": "Reading Borough Council", + "wiki_note": "Replace XXXXXXXX with your property's UPRN." + }, "ReigateAndBansteadBoroughCouncil": { "skip_get_url": true, "uprn": "68134867", @@ -764,5 +770,4 @@ "url": "https://waste-api.york.gov.uk/api/Collections/GetBinCollectionDataForUprn/", "wiki_name": "York Council" } -} - +} \ No newline at end of file diff --git a/uk_bin_collection/uk_bin_collection/councils/ReadingBoroughCouncil.py b/uk_bin_collection/uk_bin_collection/councils/ReadingBoroughCouncil.py new file mode 100644 index 0000000000..b511731aea --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/ReadingBoroughCouncil.py @@ -0,0 +1,29 @@ +from uk_bin_collection.uk_bin_collection.common import * +from uk_bin_collection.uk_bin_collection.get_bin_data import \ + AbstractGetBinDataClass + +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: + + json_result = json.loads(page.text) + + data = {"bins": []} + + for collection in json_result['collections']: + bin_type = collection['service'] + bin_collection = collection['date'] # Date format is 14/12/2023 00:00:00 + + dict_data = { + "type": bin_type.replace(" Collection Service"," Bin"), + "collectionDate": datetime.strptime(bin_collection, "%d/%m/%Y %H:%M:%S").strftime(date_format) + } + + data["bins"].append(dict_data) + + return data