diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index dec5138af7..099c3d08de 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -490,6 +490,13 @@ "wiki_name": "Huntingdon District Council", "wiki_note": "Replace XXXXXXXX with UPRN." }, + "IslingtonCouncil": { + "uprn": "5300094897", + "url": "https://www.islington.gov.uk/your-area?Postcode=unused&Uprn=5300094897", + "wiki_command_url_override": "https://www.islington.gov.uk/your-area?Postcode=unused&Uprn=XXXXXXXX", + "wiki_name": "Islington Council", + "wiki_note": "Replace XXXXXXXX with UPRN." + }, "KingstonUponThamesCouncil": { "url": "https://waste-services.kingston.gov.uk/waste/2701097", "wiki_command_url_override": "https://waste-services.kingston.gov.uk/waste/XXXXXXX", diff --git a/uk_bin_collection/uk_bin_collection/councils/IslingtonCouncil.py b/uk_bin_collection/uk_bin_collection/councils/IslingtonCouncil.py new file mode 100644 index 0000000000..f043dba453 --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/IslingtonCouncil.py @@ -0,0 +1,37 @@ +from bs4 import BeautifulSoup +from dateutil.parser import parse + +from uk_bin_collection.uk_bin_collection.common import * +from uk_bin_collection.uk_bin_collection.get_bin_data import AbstractGetBinDataClass + + +class CouncilClass(AbstractGetBinDataClass): + def parse_data(self, page: str, **kwargs) -> dict: + uprn = kwargs.get("uprn") + check_uprn(uprn) + + api_url = f"https://www.islington.gov.uk/your-area?Postcode=unused&Uprn={uprn}" + response = requests.get(api_url) + + soup = BeautifulSoup(response.text, features="html.parser") + + data = {"bins": []} + + waste_table = ( + soup.find(string="Waste and recycling collections") + .find_next("div", class_="m-toggle-content") + .find("table") + ) + + if waste_table: + rows = waste_table.find_all("tr") + for row in rows: + waste_type = row.find("th").text.strip() + next_collection = parse(row.find("td").text.strip()).date() + + data['bins'].append({ + "type": waste_type, + "collectionDate": next_collection.strftime(date_format), + }) + + return data