-
Notifications
You must be signed in to change notification settings - Fork 213
fix: Council Fix Pack - November 2025 #1679
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
23 commits
Select commit
Hold shift + click to select a range
1258d3d
fix: Rochdale Council
m26dvd bda23a7
fix: Norwich City Council
m26dvd 07a3cbf
fix: Wokingham Borough Council
m26dvd 1c6fa63
fix: London Borough of Harrow
m26dvd 7d86ba7
fix: Hart District Council
m26dvd 0c7cdd6
fix: Brighton & Hove
m26dvd 6d82c7c
docs: Update Councils.md from input.json
actions-user ced5793
fix: Brighton & Hove
m26dvd c408ecc
Merge branch 'master' of https://github.com/m26dvd/UKBinCollectionData
m26dvd 43e11ae
fix: London Borough of Hounslow
m26dvd ae00c0d
fix: Derby City Council
m26dvd 404596f
fix: Chelmsford City Council
m26dvd 2d3efea
fix: Boston Borough Council
m26dvd e2d12d7
Update BostonBoroughCouncil.py
m26dvd da7bf56
fix: Middlesborough Council
m26dvd a89320b
feat: Dumfries and Galloway Council
m26dvd 87a3ad4
fix: Newport City Council
m26dvd 1baa677
Update uk_bin_collection/uk_bin_collection/councils/LondonBoroughHarr…
m26dvd 806d2ed
Update ChelmsfordCityCouncil.py
m26dvd 2715ff4
Merge branch 'master' of https://github.com/m26dvd/UKBinCollectionData
m26dvd b7de4ca
Update uk_bin_collection/uk_bin_collection/councils/BostonBoroughCoun…
m26dvd 7ba0cc9
Update uk_bin_collection/uk_bin_collection/councils/WokinghamBoroughC…
m26dvd 75cbf30
fix: Southampton City Council
m26dvd File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
75 changes: 47 additions & 28 deletions
75
uk_bin_collection/uk_bin_collection/councils/ChelmsfordCityCouncil.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,95 +1,114 @@ | ||
| import re | ||
| import time | ||
| from datetime import datetime, timedelta | ||
|
|
||
| import requests | ||
| from bs4 import BeautifulSoup | ||
| from icalevents.icalevents import events | ||
| from selenium.webdriver.common.by import By | ||
| from selenium.webdriver.support import expected_conditions as EC | ||
| from selenium.webdriver.support.wait import WebDriverWait | ||
| from icalevents.icalevents import events | ||
|
|
||
| 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: | ||
| driver = None | ||
| try: | ||
| data = {"bins": []} | ||
| headers = {"User-Agent": "Mozilla/5.0 (Windows NT 6.1; Win64; x64)"} | ||
| user_agent = "Mozilla/5.0 (Windows NT 6.1; Win64; x64)" | ||
|
|
||
| postcode = kwargs.get("postcode") | ||
| user_paon = kwargs.get("paon") | ||
| web_driver = kwargs.get("web_driver") | ||
| headless = kwargs.get("headless") | ||
| driver = create_webdriver(web_driver, headless, None, __name__) | ||
|
|
||
| driver = create_webdriver(web_driver, headless, user_agent, __name__) | ||
| wait = WebDriverWait(driver, 30) | ||
|
|
||
| # Navigate to bin collection page | ||
| driver.get("https://www.chelmsford.gov.uk/bins-and-recycling/check-your-collection-day/") | ||
|
|
||
| driver.get( | ||
| "https://www.chelmsford.gov.uk/bins-and-recycling/check-your-collection-day/" | ||
| ) | ||
|
|
||
| # Handle cookie overlay | ||
| try: | ||
| accept_btn = wait.until( | ||
| EC.element_to_be_clickable((By.XPATH, "//*[contains(text(), 'ACCEPT')]")) | ||
| EC.element_to_be_clickable( | ||
| (By.XPATH, "//*[contains(text(), 'ACCEPT')]") | ||
| ) | ||
| ) | ||
| accept_btn.click() | ||
| time.sleep(1) | ||
| except: | ||
| except Exception as e: | ||
| # Cookie banner not present or already accepted | ||
| pass | ||
|
|
||
| # Find postcode input field (dynamic ID) | ||
| postcode_input = wait.until( | ||
| EC.presence_of_element_located((By.XPATH, "//input[contains(@id, '_keyword')]")) | ||
| EC.presence_of_element_located( | ||
| (By.XPATH, "//input[contains(@id, '_keyword')]") | ||
| ) | ||
| ) | ||
| postcode_input.clear() | ||
| postcode_input.send_keys(postcode) | ||
|
|
||
| # Click search button | ||
| submit_btn = wait.until( | ||
| EC.element_to_be_clickable((By.CLASS_NAME, "__submitButton")) | ||
| ) | ||
| submit_btn.click() | ||
|
|
||
| # Wait for results table | ||
| wait.until(EC.presence_of_element_located((By.TAG_NAME, "table"))) | ||
|
|
||
| # Get the collection round from the table row | ||
| soup = BeautifulSoup(driver.page_source, features="html.parser") | ||
|
|
||
| # Find the row containing the address | ||
| for row in soup.find_all("tr"): | ||
| if user_paon in row.get_text(): | ||
| # Extract collection round (e.g., "Tuesday B") | ||
| row_text = row.get_text() | ||
| round_match = re.search(r"(Monday|Tuesday|Wednesday|Thursday|Friday)\s+([AB])", row_text) | ||
| round_match = re.search( | ||
| r"(Monday|Tuesday|Wednesday|Thursday|Friday)\s+([AB])", row_text | ||
| ) | ||
| if round_match: | ||
| day = round_match.group(1).lower() | ||
| letter = round_match.group(2).lower() | ||
| ics_url = f"https://www.chelmsford.gov.uk/media/4ipavf0m/{day}-{letter}-calendar.ics" | ||
| ics_url = f"https://www.chelmsford.gov.uk/media/t03c4mik/{day}-{letter}-2025-26.ics" | ||
|
m26dvd marked this conversation as resolved.
|
||
| break | ||
| else: | ||
| raise ValueError(f"Could not find collection round for address: {user_paon}") | ||
|
|
||
| raise ValueError( | ||
| f"Could not find collection round for address: {user_paon}" | ||
| ) | ||
|
|
||
| # Get events from ICS file within the next 60 days | ||
| now = datetime.now() | ||
| future = now + timedelta(days=60) | ||
|
|
||
| # Parse ICS calendar | ||
| upcoming_events = events(ics_url, start=now, end=future) | ||
|
|
||
| for event in sorted(upcoming_events, key=lambda e: e.start): | ||
| if event.summary and event.start: | ||
| data["bins"].append({ | ||
| "type": event.summary, | ||
| "collectionDate": event.start.date().strftime(date_format) | ||
| }) | ||
| collections = event.summary.split(",") | ||
| for collection in collections: | ||
| data["bins"].append( | ||
| { | ||
| "type": collection.strip(), | ||
| "collectionDate": event.start.date().strftime( | ||
| date_format | ||
| ), | ||
| } | ||
| ) | ||
| except Exception as e: | ||
| print(f"An error occurred: {e}") | ||
| raise | ||
| finally: | ||
| if driver: | ||
| driver.quit() | ||
| return data | ||
|
|
||
| return data | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
uk_bin_collection/uk_bin_collection/councils/DumfriesandGallowayCouncil.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,53 @@ | ||
| import re | ||
| import time | ||
| from datetime import datetime, timedelta | ||
|
|
||
| import requests | ||
| from bs4 import BeautifulSoup | ||
| from icalevents.icalevents import events | ||
| from selenium.webdriver.common.by import By | ||
| from selenium.webdriver.support import expected_conditions as EC | ||
| 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 | ||
|
|
||
|
|
||
| class CouncilClass(AbstractGetBinDataClass): | ||
| def parse_data(self, page: str, **kwargs) -> dict: | ||
| driver = None | ||
| try: | ||
| data = {"bins": []} | ||
|
|
||
| user_uprn = kwargs.get("uprn") | ||
| check_uprn(user_uprn) | ||
|
|
||
| ics_url = f"https://www.dumfriesandgalloway.gov.uk/bins-recycling/waste-collection-schedule/download/{user_uprn}" | ||
|
|
||
| # Get events from ICS file within the next 60 days | ||
| now = datetime.now() | ||
| future = now + timedelta(days=60) | ||
|
|
||
| # Parse ICS calendar | ||
| upcoming_events = events(ics_url, start=now, end=future) | ||
|
|
||
| for event in sorted(upcoming_events, key=lambda e: e.start): | ||
| if event.summary and event.start: | ||
| collections = event.summary.split(",") | ||
| for collection in collections: | ||
| data["bins"].append( | ||
| { | ||
| "type": collection.strip(), | ||
| "collectionDate": event.start.date().strftime( | ||
| date_format | ||
| ), | ||
| } | ||
| ) | ||
| except Exception as e: | ||
| print(f"An error occurred: {e}") | ||
| raise | ||
| finally: | ||
| if driver: | ||
| driver.quit() | ||
|
|
||
| return data |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.