Skip to content

feat: add postcode lookup for durham council#2067

Open
InertiaUK wants to merge 2 commits into
robbrad:masterfrom
InertiaUK:feat/durham-postcode-lookup
Open

feat: add postcode lookup for durham council#2067
InertiaUK wants to merge 2 commits into
robbrad:masterfrom
InertiaUK:feat/durham-postcode-lookup

Conversation

@InertiaUK
Copy link
Copy Markdown
Contributor

@InertiaUK InertiaUK commented May 12, 2026

Summary

  • Users can provide either UPRN or postcode + house number
  • UPRN takes priority when provided (backward compatible)
  • Uses Durham's JSON-RPC durham.Localities.PostcodeLookup endpoint for address resolution
  • Bin data still fetched via existing Selenium page with ?uprn= param
  • Falls back to first result if no match found

Testing

  • UPRN path (backward compat): UPRN 200003218818
  • Postcode + house number: DH7 6TH + paon 2
  • Tested via API end-to-end ✅

Summary by CodeRabbit

  • New Features
    • Durham Council now accepts postcode and house number as input instead of requiring UPRN
    • UPRN is now optional and will be automatically resolved when not provided

Review Change Stack

Users can provide either UPRN or postcode + house number.
UPRN takes priority when provided (backward compatible).
Uses Durham's JSON-RPC PostcodeLookup endpoint to resolve
postcode to UPRN, then uses existing Selenium bin page.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented May 12, 2026

Warning

Review limit reached

@InertiaUK, we couldn't start this review because you've used your available PR reviews for now.

Your plan currently allows 2 reviews/hour. Refill in 25 minutes and 53 seconds.

Your organization has run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After more review capacity refills, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than trial, open-source, and free plans. In all cases, review capacity refills continuously over time.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: e954d07f-cec2-4675-bba8-264b7f4c3211

📥 Commits

Reviewing files that changed from the base of the PR and between a9ccbfa and aa5026e.

📒 Files selected for processing (2)
  • uk_bin_collection/tests/input.json
  • uk_bin_collection/uk_bin_collection/councils/DurhamCouncil.py
📝 Walkthrough

Walkthrough

Durham Council's bin collection scraper is refactored to accept postcode and house number inputs, resolving UPRN via Durham's JSON-RPC endpoint. Page fetching switches from direct HTTP requests to Selenium WebDriver with explicit waits. Bin date extraction is simplified, and test configuration is updated to document the new input requirements.

Changes

Durham Council WebDriver and postcode lookup

Layer / File(s) Summary
UPRN resolution helper and endpoint constant
uk_bin_collection/uk_bin_collection/councils/DurhamCouncil.py
AJAX_URL constant and _resolve_uprn_from_postcode helper function added. The helper performs JSON-RPC POST requests to Durham's endpoint to resolve UPRNs from a postcode (optionally filtered by normalized house number) and raises ValueError when no matches are found.
WebDriver-based parse_data with UPRN resolution
uk_bin_collection/uk_bin_collection/councils/DurhamCouncil.py
CouncilClass.parse_data refactored to extract input parameters from kwargs, resolve missing UPRN via postcode lookup when available, use Selenium WebDriver for page fetching with explicit waits for page elements, and ensure proper driver cleanup in finally block.
Bin date extraction refactoring
uk_bin_collection/uk_bin_collection/councils/DurhamCouncil.py
Bin collection date extraction simplified: regex-matched dates are parsed to datetime and directly appended to bins list with type and collectionDate fields.
Test fixture configuration update
uk_bin_collection/tests/input.json
DurhamCouncil entry updated with postcode and house_number examples, web_driver set to http://localhost:4444, and wiki_note changed to reflect postcode/house number as primary inputs with UPRN now optional.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

Possibly related PRs

  • robbrad/UKBinCollectionData#1660: Related migration from requests/BeautifulSoup to Selenium-driven parse_data flow with WebDriver waits and lifecycle handling.

Poem

🐰 A postcode whispers to Durham's RPC door,
UPRN resolved, no UPRN guessing store!
Selenium steers the browser through the page,
WebDriver waits for bins—collected, staged! 🗑️

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 50.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The pull request title accurately reflects the main change: adding postcode lookup functionality for Durham Council.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

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

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 86.67%. Comparing base (8ecf878) to head (aa5026e).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2067   +/-   ##
=======================================
  Coverage   86.67%   86.67%           
=======================================
  Files           9        9           
  Lines        1141     1141           
=======================================
  Hits          989      989           
  Misses        152      152           

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Copy Markdown
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: 4

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@uk_bin_collection/tests/input.json`:
- Line 724: The Durham note currently describes input shape but omits the new
runtime Selenium webdriver dependency; update the "wiki_note" text so it still
instructs users to provide postcode/house number/UPRN and explicitly states that
a Selenium webdriver is required at runtime because DurhamCouncil.py now always
calls create_webdriver(...). Edit the note to add a short sentence like "A
Selenium webdriver is required to run this scraper (created via
create_webdriver(...))" so readers know about the external runtime dependency.

In `@uk_bin_collection/uk_bin_collection/councils/DurhamCouncil.py`:
- Around line 38-47: The second-pass fallback currently does a raw substring
check (paon_norm in addr) which causes false positives (e.g., "2" matching
"12"); change it to match whole tokens or word boundaries instead: for each
entry in entries, normalize entry["address"] to uppercase, then either split the
address into tokens and check if paon_norm equals any token, or use a regex
word-boundary match (e.g., r'\b{paon_norm}\b') against addr; keep the initial
strict startswith checks unchanged and still return entry["uprn"] when a
whole-token/word-boundary match is found.
- Around line 54-61: The postcode-to-UPRN lookup in DurhamCouncil.__init__ only
reads kwargs.get("paon") so supplied house_number is ignored; update the
argument handling to accept house_number too (e.g., read
kwargs.get("house_number") and prefer paon if present, otherwise use
house_number) and pass that resolved value into _resolve_uprn_from_postcode when
calling it; adjust the local variables (user_paon/user_house_number) used around
the user_postcode branch so _resolve_uprn_from_postcode receives the intended
house identifier.
- Around line 29-36: The parser currently zips uprns and addrs which can
silently truncate mismatched lists; update the logic in DurhamCouncil.py to
validate that the counts of uprns and addrs are equal before building entries
(check len(uprns) == len(addrs)) and raise a ValueError with a clear message
including the postcode if they differ, instead of proceeding to the for u, a in
zip(uprns, addrs) loop that creates entries.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: bba7852b-d20d-4577-815b-fc699e266f66

📥 Commits

Reviewing files that changed from the base of the PR and between 8ecf878 and a9ccbfa.

📒 Files selected for processing (2)
  • uk_bin_collection/tests/input.json
  • uk_bin_collection/uk_bin_collection/councils/DurhamCouncil.py

Comment thread uk_bin_collection/tests/input.json Outdated
Comment thread uk_bin_collection/uk_bin_collection/councils/DurhamCouncil.py
Comment thread uk_bin_collection/uk_bin_collection/councils/DurhamCouncil.py
Comment thread uk_bin_collection/uk_bin_collection/councils/DurhamCouncil.py
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