feat: add postcode lookup for durham council#2067
Conversation
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>
|
Warning Review limit reached
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 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 configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughDurham 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. ChangesDurham Council WebDriver and postcode lookup
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes Possibly related PRs
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
Codecov Report✅ All modified and coverable lines are covered by tests. 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. |
There was a problem hiding this comment.
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
📒 Files selected for processing (2)
uk_bin_collection/tests/input.jsonuk_bin_collection/uk_bin_collection/councils/DurhamCouncil.py
Summary
durham.Localities.PostcodeLookupendpoint for address resolution?uprn=paramTesting
200003218818✅DH7 6TH+ paon2✅Summary by CodeRabbit