Skip to content

fix: Newham Council fix#1856

Open
TalhaMangarah wants to merge 3 commits intorobbrad:masterfrom
TalhaMangarah:newham-council-fix
Open

fix: Newham Council fix#1856
TalhaMangarah wants to merge 3 commits intorobbrad:masterfrom
TalhaMangarah:newham-council-fix

Conversation

@TalhaMangarah
Copy link

@TalhaMangarah TalhaMangarah commented Feb 16, 2026

This PR contains 2 fixes and I've also added one type of bin collection (food waste)

Fixes:

  • disable SSL verification to resolve certificate verification error
    • HA was giving me the below error so bypassing with verify=False
      Failed setup, will retry: Unexpected error: HTTPSConnectionPool(host='bincollection.newham.gov.uk', port=443): Max retries exceeded with url: /Details/Index/XXXXXXXX (Caused by SSLError(SSLCertVerificationError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate (_ssl.c:1032)')))
    • seems to be due to an incomplete cert chain
  • correct datetime parsing from DD/MM/YYYY to MM/DD/YYYY
    • for some reason, the date format was changed to MM/DD/YYYY so changed the format

Features:

  • Newham is rolling out a food waste bin so although not all residents have it yet, the collection website does display a date if your UPRN has one

Summary by CodeRabbit

  • New Features

    • Added support for tracking Food Waste bin collection alongside existing bin types.
  • Bug Fixes

    • Corrected collection date parsing to ensure accurate date recognition.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Feb 16, 2026

📝 Walkthrough

Walkthrough

Modified NewhamCouncil.py to support food waste bin collection. Changes include disabling SSL verification, adding food waste bin type to recognized collection types, parsing food waste bin data from the page structure, and adjusting the date parsing format from day-first to month-first format.

Changes

Cohort / File(s) Summary
Newham Council Scraper Enhancement
uk_bin_collection/uk_bin_collection/councils/NewhamCouncil.py
Added support for Food Waste bin collection detection. Modified date parsing format from "%d/%m/%Y" to "%m/%d/%Y". Disabled SSL certificate verification. Expanded bin type recognition to include "Food Waste" alongside existing "Domestic" and "Recycling" types.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

🐰 A carrot for compost, the waste now is tracked,
Food scraps find their purpose, no longer unpacked,
Newham's bins align with a date-format switch,
SSL verification loosened—a practical glitch,
Waste streams now flowing with code-rabbit's touch! 🥬

🚥 Pre-merge checks | ✅ 2 | ❌ 2

❌ Failed checks (1 warning, 1 inconclusive)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Title check ❓ Inconclusive The title is vague and generic, using 'fix' without specifying what is being fixed, making it unclear to someone scanning history. Use a more specific title that describes the actual changes, such as 'fix: Newham Council SSL verification and date parsing' or 'feat: Add food waste support and fix SSL verification for Newham Council'.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Merge Conflict Detection ✅ Passed ✅ No merge conflicts detected when merging into master

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

Tip

Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@uk_bin_collection/uk_bin_collection/councils/NewhamCouncil.py`:
- Around line 47-58: The parsing loop for sections (variables: header,
bin_type_element, array_expected_types, date) assumes a rigid DOM and can raise
AttributeError when chaining item.find_next("p", {"class":
"card-text"}).find_next("mark").next_sibling; modify the loop to defensively
handle missing nodes by either (a) checking each intermediate value is not None
before accessing its children (verify header, bin_p = item.find_next("p",
{"class":"card-text"}), mark = bin_p.find_next("mark"), and mark.next_sibling)
and only then assign date, or (b) wrap the inner parsing in a try/except
AttributeError that logs/continues on failure; ensure the check for bin_type in
array_expected_types remains and that malformed cards are skipped without
raising.
🧹 Nitpick comments (2)
uk_bin_collection/uk_bin_collection/councils/NewhamCouncil.py (2)

1-1: Suppress InsecureRequestWarning since SSL verification is intentionally disabled.

urllib3 is imported but unused. Since verify=False will emit an InsecureRequestWarning on every request, you likely intended to suppress it. Also consider adding a code comment explaining why verification is disabled (incomplete certificate chain) so future maintainers don't silently remove it.

🛡️ Proposed fix
 import urllib3
+urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
 from bs4 import BeautifulSoup

Also applies to: 22-22


24-24: Pre-existing: soup.prettify is a no-op without parentheses.

This is a method reference, not a call. It should be soup.prettify() if the intent is to prettify, or removed entirely since the result isn't used.

Comment on lines 47 to 58
for item in sections:
header = item.find("div", {"class": "card-header"})
bin_type_element = header.find_next("b")
if bin_type_element is not None:
bin_type = bin_type_element.text
array_expected_types = ["Domestic", "Recycling"]
array_expected_types = ["Domestic", "Recycling", "Food Waste"]
if bin_type in array_expected_types:
date = (
item.find_next("p", {"class": "card-text"})
.find_next("mark")
.next_sibling.strip()
)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Chained attribute access can raise AttributeError if the food waste card has a different DOM structure.

header, bin_type_element, and the find_next("p")...find_next("mark").next_sibling chain all assume a specific HTML structure. If the food waste card layout differs even slightly (e.g., missing <mark> tag), this will throw an unhandled AttributeError. This was a pre-existing risk for domestic/recycling but the new food waste type increases the surface area.

Consider wrapping the inner parsing in a try/except or adding None guards.

🤖 Prompt for AI Agents
In `@uk_bin_collection/uk_bin_collection/councils/NewhamCouncil.py` around lines
47 - 58, The parsing loop for sections (variables: header, bin_type_element,
array_expected_types, date) assumes a rigid DOM and can raise AttributeError
when chaining item.find_next("p", {"class":
"card-text"}).find_next("mark").next_sibling; modify the loop to defensively
handle missing nodes by either (a) checking each intermediate value is not None
before accessing its children (verify header, bin_p = item.find_next("p",
{"class":"card-text"}), mark = bin_p.find_next("mark"), and mark.next_sibling)
and only then assign date, or (b) wrap the inner parsing in a try/except
AttributeError that logs/continues on failure; ensure the check for bin_type in
array_expected_types remains and that malformed cards are skipped without
raising.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant