From 9b3e2f68bc3ede68a5a09fe05a705887b8c04c9a Mon Sep 17 00:00:00 2001 From: Paul Hardacre Date: Mon, 27 Jan 2025 19:39:31 +0000 Subject: [PATCH 1/2] feat: implement Medway Council (#1021) --- uk_bin_collection/tests/input.json | 6 +++ .../councils/MedwayCouncil.py | 40 +++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 uk_bin_collection/uk_bin_collection/councils/MedwayCouncil.py diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index 2a925ebc7a..328d25f505 100755 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -1123,6 +1123,12 @@ "wiki_name": "Mansfield District Council", "wiki_note": "Pass the UPRN. You can find it using [FindMyAddress](https://www.findmyaddress.co.uk/search)." }, + "MedwayCouncil": { + "uprn": "200000907059", + "url": "https://www.medway.gov.uk/homepage/45/check_your_waste_collection_day", + "wiki_name": "MedwayCouncil", + "wiki_note": "Pass the UPRN. You can find it using [FindMyAddress](https://www.findmyaddress.co.uk/search)." + }, "MertonCouncil": { "url": "https://myneighbourhood.merton.gov.uk/wasteservices/WasteServices.aspx?ID=25936129", "wiki_command_url_override": "https://myneighbourhood.merton.gov.uk/Wasteservices/WasteServices.aspx?ID=XXXXXXXX", diff --git a/uk_bin_collection/uk_bin_collection/councils/MedwayCouncil.py b/uk_bin_collection/uk_bin_collection/councils/MedwayCouncil.py new file mode 100644 index 0000000000..6df21ec6e0 --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/MedwayCouncil.py @@ -0,0 +1,40 @@ +import json +from datetime import timedelta + +import requests + +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: + user_uprn = kwargs.get("uprn") + check_uprn(user_uprn) + + api_url = f"https://api.medway.gov.uk/api/waste/getwasteday/{user_uprn}" + + response = requests.get(api_url) + + data = {"bins": []} + + # If the response is 200, then we can parse the data; if not, we return an empty dict + if response.status_code == 200: + json_data = json.loads(response.text) + if json_data: + next_date = datetime.strptime( + json_data["nextCollection"], "%Y-%m-%dT%H:%M:%S%z" + ) + dict_data = { + "type": "All bins", + "collectionDate": next_date.strftime(date_format), + } + data["bins"].append(dict_data) + + return data From 0b101d155d3ee54dde55fc14617c4e1a02eaa065 Mon Sep 17 00:00:00 2001 From: Paul Hardacre Date: Mon, 27 Jan 2025 20:16:37 +0000 Subject: [PATCH 2/2] fix: Forgot to include skip_get_url --- uk_bin_collection/tests/input.json | 1 + 1 file changed, 1 insertion(+) diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index 328d25f505..f7729f48d7 100755 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -1124,6 +1124,7 @@ "wiki_note": "Pass the UPRN. You can find it using [FindMyAddress](https://www.findmyaddress.co.uk/search)." }, "MedwayCouncil": { + "skip_get_url": true, "uprn": "200000907059", "url": "https://www.medway.gov.uk/homepage/45/check_your_waste_collection_day", "wiki_name": "MedwayCouncil",