From 52322429dd68fc35b3ed890677f09df0cefde51c Mon Sep 17 00:00:00 2001 From: m26dvd <31007572+m26dvd@users.noreply.github.com> Date: Fri, 18 Oct 2024 15:34:13 +0100 Subject: [PATCH 1/5] feat: Adding Swindon Borough Council fix: #900 --- uk_bin_collection/tests/input.json | 7 +++ .../councils/SwindonBoroughCouncil.py | 56 +++++++++++++++++++ 2 files changed, 63 insertions(+) create mode 100644 uk_bin_collection/uk_bin_collection/councils/SwindonBoroughCouncil.py diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index e0441f4d8b..c0edb10b82 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -1183,6 +1183,13 @@ "url": "https://www1.swansea.gov.uk/recyclingsearch/", "wiki_name": "SwanseaCouncil" }, + "SwindonBoroughCouncil": { + "url": "https://www.swindon.gov.uk", + "wiki_command_url_override": "https://www.swindon.gov.uk", + "uprn": "10022793351", + "wiki_name": "Swindon Borough Council", + "wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN." + }, "TamesideMBCouncil": { "skip_get_url": true, "uprn": "100012835362", diff --git a/uk_bin_collection/uk_bin_collection/councils/SwindonBoroughCouncil.py b/uk_bin_collection/uk_bin_collection/councils/SwindonBoroughCouncil.py new file mode 100644 index 0000000000..db33a65e19 --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/SwindonBoroughCouncil.py @@ -0,0 +1,56 @@ +import time + +import requests +from bs4 import BeautifulSoup + +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://www.swindon.gov.uk/info/20122/rubbish_and_recycling_collection_days?addressList={user_uprn}&uprnSubmit=Yes" + + # Make the GET request + response = requests.get(URI) + + # Parse the JSON response + soup = BeautifulSoup(response.text, "html.parser") + + bin_collection_content = soup.find_all( + "div", {"class": "bin-collection-content"} + ) + for content in bin_collection_content: + content_left = content.find("div", {"class": "content-left"}) + content_right = content.find("div", {"class": "content-right"}) + if content_left and content_right: + + bin_types = content_left.find("h3").text.split(" and ") + for bin_type in bin_types: + + collection_date = datetime.strptime( + content_right.find( + "span", {"class": "nextCollectionDate"} + ).text, + "%A, %d %B %Y", + ).strftime(date_format) + + dict_data = { + "type": bin_type, + "collectionDate": collection_date, + } + bindata["bins"].append(dict_data) + + return bindata From fff1bb2da536a82ca84ed1ee0baa9cd557730be3 Mon Sep 17 00:00:00 2001 From: m26dvd <31007572+m26dvd@users.noreply.github.com> Date: Sun, 20 Oct 2024 21:41:15 +0100 Subject: [PATCH 2/5] feat: Adding Canterbury City Council fix: #590 --- uk_bin_collection/tests/input.json | 7 +++ .../councils/CanterburyCityCouncil.py | 54 +++++++++++++++++++ 2 files changed, 61 insertions(+) create mode 100644 uk_bin_collection/uk_bin_collection/councils/CanterburyCityCouncil.py diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index 67169d978e..651051b82f 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -201,6 +201,13 @@ "wiki_name": "Cannock Chase District Council", "wiki_note": "To get the UPRN, you can use [FindMyAddress](https://www.findmyaddress.co.uk/search)" }, + "CanterburyCityCouncil": { + "url": "https://www.canterbury.gov.uk", + "wiki_command_url_override": "https://www.canterbury.gov.uk", + "uprn": "10094583181", + "wiki_name": "Canterbury City Council", + "wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN." + }, "CardiffCouncil": { "skip_get_url": true, "uprn": "100100112419", diff --git a/uk_bin_collection/uk_bin_collection/councils/CanterburyCityCouncil.py b/uk_bin_collection/uk_bin_collection/councils/CanterburyCityCouncil.py new file mode 100644 index 0000000000..6f9fafb0b0 --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/CanterburyCityCouncil.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": []} + + data = {"uprn": user_uprn, "usrn": "1"} + + URI = ( + "https://zbr7r13ke2.execute-api.eu-west-2.amazonaws.com/Beta/get-bin-dates" + ) + + # Make the GET request + response = requests.post(URI, json=data) + response.raise_for_status() + + # Parse the JSON response + bin_collection = json.loads(response.json()["dates"]) + collections = { + "General": bin_collection["blackBinDay"], + "Recycling": bin_collection["recyclingBinDay"], + "Food": bin_collection["foodBinDay"], + "Garden": bin_collection["gardenBinDay"], + } + # Loop through each collection in bin_collection + for collection in collections: + print(collection) + + if len(collections[collection]) <= 0: + continue + for date in collections[collection]: + date = ( + datetime.strptime(date, "%Y-%m-%dT%H:%M:%S").strftime("%d/%m/%Y"), + ) + dict_data = {"type": collection, "collectionDate": date[0]} + bindata["bins"].append(dict_data) + + return bindata From 06ed6a94c3f5b97320acd4a672a994e3df2247d4 Mon Sep 17 00:00:00 2001 From: m26dvd <31007572+m26dvd@users.noreply.github.com> Date: Sun, 20 Oct 2024 23:10:19 +0100 Subject: [PATCH 3/5] feat: Adding Aberdeenshire Council fix: #659 --- uk_bin_collection/tests/input.json | 7 +++ .../councils/AberdeenshireCouncil.py | 52 +++++++++++++++++++ 2 files changed, 59 insertions(+) create mode 100644 uk_bin_collection/uk_bin_collection/councils/AberdeenshireCouncil.py diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index 651051b82f..7121a808c1 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -1,4 +1,11 @@ { + "AberdeenshireCouncil": { + "url": "https://online.aberdeenshire.gov.uk", + "wiki_command_url_override": "https://online.aberdeenshire.gov.uk", + "uprn": "151176430", + "wiki_name": "Aberdeenshire Council", + "wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN." + }, "AdurAndWorthingCouncils": { "url": "https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address=100061878829", "wiki_command_url_override": "https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address=XXXXXXXX", diff --git a/uk_bin_collection/uk_bin_collection/councils/AberdeenshireCouncil.py b/uk_bin_collection/uk_bin_collection/councils/AberdeenshireCouncil.py new file mode 100644 index 0000000000..a797c2ce05 --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/AberdeenshireCouncil.py @@ -0,0 +1,52 @@ +import requests +from bs4 import BeautifulSoup + +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://online.aberdeenshire.gov.uk/Apps/Waste-Collections/Routes/Route/{user_uprn}" + + # Make the GET request + response = requests.get(URI) + + soup = BeautifulSoup(response.content, features="html.parser") + soup.prettify() + + for collection in soup.find("table").find("tbody").find_all("tr"): + th = collection.find("th") + if th: + continue + td = collection.find_all("td") + collection_date = datetime.strptime( + td[0].text, + "%d/%m/%Y %A", + ) + bin_type = td[1].text.split(" and ") + + for bin in bin_type: + dict_data = { + "type": bin, + "collectionDate": collection_date.strftime(date_format), + } + bindata["bins"].append(dict_data) + + bindata["bins"].sort( + key=lambda x: datetime.strptime(x.get("collectionDate"), "%d/%m/%Y") + ) + + return bindata From 2b2856a6bee1e27ca30c324f9677f427ad5f7c0d Mon Sep 17 00:00:00 2001 From: m26dvd <31007572+m26dvd@users.noreply.github.com> Date: Sun, 20 Oct 2024 23:26:45 +0100 Subject: [PATCH 4/5] feat: Adding West Oxfordshire District Council fix: #694 --- uk_bin_collection/tests/input.json | 9 ++ .../WestOxfordshireDistrictCouncil.py | 113 ++++++++++++++++++ wiki/Councils.md | 61 ++++++++++ 3 files changed, 183 insertions(+) create mode 100644 uk_bin_collection/uk_bin_collection/councils/WestOxfordshireDistrictCouncil.py diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index 7121a808c1..8a7e59b889 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -1390,6 +1390,15 @@ "url": "https://www.northampton.gov.uk/info/200084/bins-waste-and-recycling/1602/check-your-collection-day", "wiki_name": "West Northamptonshire Council" }, + "WestOxfordshireDistrictCouncil": { + "house_number": "24", + "postcode": "OX28 1YA", + "skip_get_url": true, + "url": "https://community.westoxon.gov.uk/s/waste-collection-enquiry", + "web_driver": "http://selenium:4444", + "wiki_name": "West Oxfordshire District Council", + "wiki_note": "Pass the full address in the house number and postcode in" + }, "WestSuffolkCouncil": { "postcode": "IP28 6DR", "skip_get_url": true, diff --git a/uk_bin_collection/uk_bin_collection/councils/WestOxfordshireDistrictCouncil.py b/uk_bin_collection/uk_bin_collection/councils/WestOxfordshireDistrictCouncil.py new file mode 100644 index 0000000000..e6439c4c34 --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/WestOxfordshireDistrictCouncil.py @@ -0,0 +1,113 @@ +import time +from datetime import datetime + +from bs4 import BeautifulSoup +from selenium.webdriver.common.by import By +from selenium.webdriver.common.keys import Keys +from selenium.webdriver.support import expected_conditions as EC +from selenium.webdriver.support.ui import Select +from selenium.webdriver.support.wait import WebDriverWait + +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: + driver = None + try: + page = "https://community.westoxon.gov.uk/s/waste-collection-enquiry" + + data = {"bins": []} + + house_number = kwargs.get("paon") + postcode = kwargs.get("postcode") + full_address = f"{house_number}, {postcode}" + web_driver = kwargs.get("web_driver") + headless = kwargs.get("headless") + + # Create Selenium webdriver + driver = create_webdriver(web_driver, headless, None, __name__) + driver.get(page) + + # If you bang in the house number (or property name) and postcode in the box it should find your property + wait = WebDriverWait(driver, 60) + address_entry_field = wait.until( + EC.presence_of_element_located( + (By.XPATH, '//*[@id="combobox-input-19"]') + ) + ) + + address_entry_field.send_keys(str(full_address)) + + address_entry_field = wait.until( + EC.element_to_be_clickable((By.XPATH, '//*[@id="combobox-input-19"]')) + ) + address_entry_field.click() + address_entry_field.send_keys(Keys.BACKSPACE) + address_entry_field.send_keys(str(full_address[len(full_address) - 1])) + + first_found_address = wait.until( + EC.element_to_be_clickable( + (By.XPATH, '//*[@id="dropdown-element-19"]/ul') + ) + ) + + first_found_address.click() + # Wait for the 'Select your property' dropdown to appear and select the first result + next_btn = wait.until( + EC.element_to_be_clickable((By.XPATH, "//lightning-button/button")) + ) + next_btn.click() + bin_data = wait.until( + EC.presence_of_element_located( + (By.XPATH, "//span[contains(text(), 'Container')]") + ) + ) + + soup = BeautifulSoup(driver.page_source, features="html.parser") + + rows = soup.find_all("tr", class_="slds-hint-parent") + current_year = datetime.now().year + + for row in rows: + columns = row.find_all("td") + if columns: + container_type = row.find("th").text.strip() + collection_day = re.sub( + r"[^a-zA-Z0-9,\s]", "", columns[0].get_text() + ).strip() + + # Parse the date from the string + parsed_date = datetime.strptime(collection_day, "%a, %d %B") + if parsed_date < datetime( + parsed_date.year, parsed_date.month, parsed_date.day + ): + parsed_date = parsed_date.replace(year=current_year + 1) + else: + parsed_date = parsed_date.replace(year=current_year) + # Format the date as %d/%m/%Y + formatted_date = parsed_date.strftime("%d/%m/%Y") + + # Add the bin type and collection date to the 'data' dictionary + data["bins"].append( + {"type": container_type, "collectionDate": formatted_date} + ) + except Exception as e: + # Here you can log the exception if needed + print(f"An error occurred: {e}") + # Optionally, re-raise the exception if you want it to propagate + raise + finally: + # This block ensures that the driver is closed regardless of an exception + if driver: + driver.quit() + return data diff --git a/wiki/Councils.md b/wiki/Councils.md index 455348f7d2..29399e78c7 100644 --- a/wiki/Councils.md +++ b/wiki/Councils.md @@ -10,6 +10,7 @@ For scripts that need postcodes, these should be provided in double quotes and w This document is still a work in progress, don't worry if your council isn't listed - it will be soon! ## Contents +- [Aberdeenshire Council](#aberdeenshire-council) - [Adur and Worthing Councils](#adur-and-worthing-councils) - [Armagh Banbridge Craigavon Council](#armagh-banbridge-craigavon-council) - [Arun Council](#arun-council) @@ -37,6 +38,7 @@ This document is still a work in progress, don't worry if your council isn't lis - [Bury Council](#bury-council) - [Calderdale Council](#calderdale-council) - [Cannock Chase District Council](#cannock-chase-district-council) +- [Canterbury City Council](#canterbury-city-council) - [Cardiff Council](#cardiff-council) - [Castlepoint District Council](#castlepoint-district-council) - [Charnwood Borough Council](#charnwood-borough-council) @@ -109,6 +111,7 @@ This document is still a work in progress, don't worry if your council isn't lis - [Mansfield District Council](#mansfield-district-council) - [Merton Council](#merton-council) - [Mid and East Antrim Borough Council](#mid-and-east-antrim-borough-council) +- [Midlothian Council](#midlothian-council) - [Mid Sussex District Council](#mid-sussex-district-council) - [Milton Keynes City Council](#milton-keynes-city-council) - [Mole Valley District Council](#mole-valley-district-council) @@ -176,6 +179,7 @@ This document is still a work in progress, don't worry if your council isn't lis - [Sunderland City Council](#sunderland-city-council) - [Swale Borough Council](#swale-borough-council) - [SwanseaCouncil](#swanseacouncil) +- [Swindon Borough Council](#swindon-borough-council) - [Tameside Metropolitan Borough Council](#tameside-metropolitan-borough-council) - [Tandridge District Council](#tandridge-district-council) - [Telford and Wrekin Co-operative Council](#telford-and-wrekin-co-operative-council) @@ -201,6 +205,7 @@ This document is still a work in progress, don't worry if your council isn't lis - [West Lothian Council](#west-lothian-council) - [West Morland And Furness Council](#west-morland-and-furness-council) - [West Northamptonshire Council](#west-northamptonshire-council) +- [West Oxfordshire District Council](#west-oxfordshire-district-council) - [West Suffolk Council](#west-suffolk-council) - [Wigan Borough Council](#wigan-borough-council) - [Wiltshire Council](#wiltshire-council) @@ -215,6 +220,17 @@ This document is still a work in progress, don't worry if your council isn't lis --- +### Aberdeenshire Council +```commandline +python collect_data.py AberdeenshireCouncil https://online.aberdeenshire.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. + +--- + ### Adur and Worthing Councils ```commandline python collect_data.py AdurAndWorthingCouncils https://www.adur-worthing.gov.uk/bin-day/?brlu-selected-address=XXXXXXXX @@ -535,6 +551,17 @@ Note: To get the UPRN, you can use [FindMyAddress](https://www.findmyaddress.co. --- +### Canterbury City Council +```commandline +python collect_data.py CanterburyCityCouncil https://www.canterbury.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. + +--- + ### Cardiff Council ```commandline python collect_data.py CardiffCouncil https://www.cardiff.gov.uk/ENG/resident/Rubbish-and-recycling/When-are-my-bins-collected/Pages/default.aspx -s -u XXXXXXXX @@ -1356,6 +1383,15 @@ Note: Pass the house name/number plus the name of the street with the postcode p --- +### Midlothian Council +```commandline +python collect_data.py MidlothianCouncil https://www.midlothian.gov.uk/directory_record/XXXXXX/XXXXXX +``` + +Note: Follow the instructions [here](https://www.midlothian.gov.uk/info/1054/bins_and_recycling/343/bin_collection_days) until you get the page that shows the weekly collections for your address then copy the URL and replace the URL in the command. + +--- + ### Mid Sussex District Council ```commandline python collect_data.py MidSussexDistrictCouncil https://www.midsussex.gov.uk/waste-recycling/bin-collection/ -s -p "XXXX XXX" -n XX -w http://HOST:PORT/ @@ -2086,6 +2122,17 @@ Additional parameters: --- +### Swindon Borough Council +```commandline +python collect_data.py SwindonBoroughCouncil https://www.swindon.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. + +--- + ### Tameside Metropolitan Borough Council ```commandline python collect_data.py TamesideMBCouncil http://lite.tameside.gov.uk/BinCollections/CollectionService.svc/GetBinCollection -s -u XXXXXXXX @@ -2369,6 +2416,20 @@ Additional parameters: --- +### West Oxfordshire District Council +```commandline +python collect_data.py WestOxfordshireDistrictCouncil https://community.westoxon.gov.uk/s/waste-collection-enquiry -s -p "XXXX XXX" -n XX -w http://HOST:PORT/ +``` +Additional parameters: +- `-s` - skip get URL +- `-p` - postcode +- `-n` - house number +- `-w` - remote Selenium web driver URL (required for Home Assistant) + +Note: Pass the full address in the house number and postcode in + +--- + ### West Suffolk Council ```commandline python collect_data.py WestSuffolkCouncil https://maps.westsuffolk.gov.uk/MyWestSuffolk.aspx -s -u XXXXXXXX -p "XXXX XXX" From a2b35bb201283309b90dbfa039347e2879d1086a Mon Sep 17 00:00:00 2001 From: m26dvd <31007572+m26dvd@users.noreply.github.com> Date: Sun, 20 Oct 2024 23:51:20 +0100 Subject: [PATCH 5/5] feat: Adding Luton Borough Council fix: #697 --- uk_bin_collection/tests/input.json | 7 ++ .../councils/LutonBoroughCouncil.py | 81 +++++++++++++++++++ wiki/Councils.md | 12 +++ 3 files changed, 100 insertions(+) create mode 100644 uk_bin_collection/uk_bin_collection/councils/LutonBoroughCouncil.py diff --git a/uk_bin_collection/tests/input.json b/uk_bin_collection/tests/input.json index 8a7e59b889..957ab622a5 100644 --- a/uk_bin_collection/tests/input.json +++ b/uk_bin_collection/tests/input.json @@ -695,6 +695,13 @@ "wiki_name": "London Borough Redbridge", "wiki_note": "Follow the instructions [here](https://my.redbridge.gov.uk/RecycleRefuse) until you get the page listing your \"Address\" then copy the entire address text and use that in the house number field." }, + "LutonBoroughCouncil": { + "url": "https://myforms.luton.gov.uk", + "wiki_command_url_override": "https://myforms.luton.gov.uk", + "uprn": "100080155778", + "wiki_name": "Luton Borough Council", + "wiki_note": "You will need to use [FindMyAddress](https://www.findmyaddress.co.uk/search) to find the UPRN." + }, "MaldonDistrictCouncil": { "skip_get_url": true, "uprn": "100090557253", diff --git a/uk_bin_collection/uk_bin_collection/councils/LutonBoroughCouncil.py b/uk_bin_collection/uk_bin_collection/councils/LutonBoroughCouncil.py new file mode 100644 index 0000000000..7dda0c6d8a --- /dev/null +++ b/uk_bin_collection/uk_bin_collection/councils/LutonBoroughCouncil.py @@ -0,0 +1,81 @@ +import time + +import requests +from bs4 import BeautifulSoup + +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": []} + + SESSION_URL = "https://myforms.luton.gov.uk/authapi/isauthenticated?uri=https%253A%252F%252Fmyforms.luton.gov.uk%252Fservice%252FFind_my_bin_collection_date&hostname=myforms.luton.gov.uk&withCredentials=true" + + API_URL = "https://myforms.luton.gov.uk/apibroker/runLookup" + + data = { + "formValues": { + "Find my bin collection date": { + "id": { + "value": f"1-{user_uprn}", + }, + }, + } + } + + headers = { + "Content-Type": "application/json", + "Accept": "application/json", + "User-Agent": "Mozilla/5.0", + "X-Requested-With": "XMLHttpRequest", + "Referer": "https://myforms.luton.gov.uk/fillform/?iframe_id=fillform-frame-1&db_id=", + } + s = requests.session() + r = s.get(SESSION_URL) + r.raise_for_status() + session_data = r.json() + sid = session_data["auth-session"] + params = { + "id": "65cb710f8d525", + "repeat_against": "", + "noRetry": "true", + "getOnlyTokens": "undefined", + "log_id": "", + "app_name": "AF-Renderer::Self", + # unix_timestamp + "_": str(int(time.time() * 1000)), + "sid": sid, + } + r = s.post(API_URL, json=data, headers=headers, params=params) + r.raise_for_status() + data = r.json() + rows_data = data["integration"]["transformed"]["rows_data"][f"{user_uprn}"] + + soup = BeautifulSoup(rows_data["html"], features="html.parser") + soup.prettify() + for collection in soup.find_all("tr"): + tds = collection.find_all("td") + bin_type = tds[1].text + collection_date = datetime.strptime( + tds[0].text, + "%A %d %b %Y", + ) + dict_data = { + "type": bin_type, + "collectionDate": collection_date.strftime(date_format), + } + bindata["bins"].append(dict_data) + + return bindata diff --git a/wiki/Councils.md b/wiki/Councils.md index 29399e78c7..e0a82f722e 100644 --- a/wiki/Councils.md +++ b/wiki/Councils.md @@ -105,6 +105,7 @@ This document is still a work in progress, don't worry if your council isn't lis - [London Borough Hounslow](#london-borough-hounslow) - [London Borough Lambeth](#london-borough-lambeth) - [London Borough Redbridge](#london-borough-redbridge) +- [Luton Borough Council](#luton-borough-council) - [Maldon District Council](#maldon-district-council) - [Malvern Hills District Council](#malvern-hills-district-council) - [Manchester City Council](#manchester-city-council) @@ -1321,6 +1322,17 @@ Note: Follow the instructions [here](https://my.redbridge.gov.uk/RecycleRefuse) --- +### Luton Borough Council +```commandline +python collect_data.py LutonBoroughCouncil https://myforms.luton.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. + +--- + ### Maldon District Council ```commandline python collect_data.py MaldonDistrictCouncil https://maldon.suez.co.uk/maldon/ServiceSummary -s -u XXXXXXXX