From a61de4f5e269a9d7b80894e7eb81c5b6e8fef11a Mon Sep 17 00:00:00 2001 From: m26dvd <31007572+m26dvd@users.noreply.github.com> Date: Thu, 10 Oct 2024 11:58:11 +0100 Subject: [PATCH] feat: Adding Falkirk Council fix: #761 --- uk_bin_collection/tests/input.json | 7 +++ .../councils/FalkirkCouncil.py | 54 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 uk_bin_collection/uk_bin_collection/councils/FalkirkCouncil.py diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index 1fc7a8abc9..24617db29b 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -431,6 +431,13 @@ "url": "https://map.erewash.gov.uk/isharelive.web/myerewash.aspx", "wiki_name": "Erewash Borough Council" }, + "FalkirkCouncil": { + "url": "https://www.falkirk.gov.uk", + "wiki_command_url_override": "https://www.falkirk.gov.uk", + "uprn": "136065818", + "wiki_name": "Falkirk Council", + "wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN." + }, "FarehamBoroughCouncil": { "postcode": "PO14 4NR", "skip_get_url": true, diff --git a/uk_bin_collection/uk_bin_collection/councils/FalkirkCouncil.py b/uk_bin_collection/uk_bin_collection/councils/FalkirkCouncil.py new file mode 100644 index 0000000000..977d7ae2b9 --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/FalkirkCouncil.py @@ -0,0 +1,54 @@ +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 = f"https://recycling.falkirk.gov.uk/api/collections/{user_uprn}" + + # Make the GET request + response = requests.get(URI) + + # Parse the JSON response + bin_collection = response.json() + + # Loop through each collection in bin_collection + for collection in bin_collection["collections"]: + bin_type = collection["type"] + collection_dates = collection["dates"] + + # Loop through the dates for each collection type + for date in collection_dates: + print(f"Bin Type: {bin_type}") + print(f"Collection Date: {date}") + + dict_data = { + "type": bin_type, + "collectionDate": datetime.strptime( + date, + "%Y-%m-%d", + ).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