Skip to content

feat: EastDevonDC - add postcode + house number lookup via addressfinder#2062

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

feat: EastDevonDC - add postcode + house number lookup via addressfinder#2062
InertiaUK wants to merge 2 commits into
robbrad:masterfrom
InertiaUK:feat/eastdevon-postcode-lookup

Conversation

@InertiaUK
Copy link
Copy Markdown
Contributor

@InertiaUK InertiaUK commented May 12, 2026

Summary

  • Users can now provide either UPRN or postcode + house number/name — whichever they have.
  • UPRN takes priority when provided (backward compatible with existing users).
  • When postcode is given, calls East Devons /addressfinder?qtype=bins&term={postcode}` endpoint which returns addresses with UPRNs. Matches by house number/name, then uses the resolved UPRN with the existing calendar page.
  • Falls back to first address if no match found.

How it works

  1. If postcode provided → GET /addressfinder?qtype=bins&term={postcode} → JSON with addresses + UPRNs
  2. Match by UPRN (if given) or house number/name in label field
  3. Use resolved UPRN with existing ?UPRN=X calendar page

Testing

  • UPRN path (backward compat): UPRN 010000273781
  • Postcode + house name: EX10 8DP + paon EGYPT
  • API end-to-end via bin-resolve-v2.php (22 bins returned) ✅

Summary by CodeRabbit

  • New Features

    • Address lookup for East Devon now supports postcode + house number resolution (UPRN optional) and normalises the resolved UPRN.
  • Bug Fixes

    • Improved timeout and error handling for address lookups.
    • Parsing now reliably returns an empty bins payload when calendar data is missing.
  • Chores

    • Updated test/config guidance for East Devon to use postcode and house number.

Review Change Stack

@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 20 minutes and 42 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: fb067338-e1c6-4e07-b2aa-21033181bf0f

📥 Commits

Reviewing files that changed from the base of the PR and between b71eb9f and 4b0fe1c.

📒 Files selected for processing (1)
  • uk_bin_collection/uk_bin_collection/councils/EastDevonDC.py
📝 Walkthrough

Walkthrough

The East Devon parser is refactored to extract address matching and calendar fetching into helpers, remove the unused pandas import, and change parse_data to resolve UPRNs from postcode/house number via the East Devon addressfinder API before delegating calendar retrieval to the new parser.

Changes

EastDevonDC Parser Refactor

Layer / File(s) Summary
Imports and address resolution helper
uk_bin_collection/uk_bin_collection/councils/EastDevonDC.py
Imports updated to remove pandas and add requests. New _match_address() helper selects an address from addressfinder results by zero-padded UPRN or case-normalized PAON match, returning the first address as fallback.
Calendar fetching and parsing helper
uk_bin_collection/uk_bin_collection/councils/EastDevonDC.py
New _parse_calendar_page() helper fetches the calendar HTML by UPRN URL, extracts collection dates and bin types (including bank-holiday replacement labels), and returns {"bins": []} when the calendar list element is absent.
Main parse_data refactor
uk_bin_collection/uk_bin_collection/councils/EastDevonDC.py, uk_bin_collection/tests/input.json
parse_data now optionally resolves user_uprn from provided postcode (via East Devon addressfinder API with timeout=30 and raise_for_status), requires and zero-pads a 12-digit UPRN or raises ValueError, constructs the future-collections-calendar URL, and delegates parsing to _parse_calendar_page. Test/config input for EastDevonDC updated to include postcode and house_number and adjusted wiki_note/stored uprn.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A rabbit hops through Devon lanes at dawn,
Resolves a postcode, finds the UPRN,
Parsers split like carrots into neat bits,
No pandas now—just tidy helper wits,
Bins march home on calendar-lined lawns.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 66.67% 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 title directly and accurately describes the main change: adding postcode and house number lookup via addressfinder to the EastDevonDC scraper, which aligns with the core refactoring and new functionality introduced.
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.

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/uk_bin_collection/councils/EastDevonDC.py`:
- Line 16: Normalize the address UPRN before comparing to the zero-padded target
to avoid false negatives: when checking addr.get("UPRN") against uprn_str in
EastDevonDC, coerce the fetched UPRN to a canonical form (e.g.,
str(addr.get("UPRN","")).zfill(12) or by stripping leading zeros from both
sides) and compare that normalized value to uprn_str so matched addresses are
correctly found.
- Around line 45-46: The code currently returns the empty result `data` when
`calendar_collection` is missing, which hides parsing failures; instead, in the
parsing function where `calendar_collection` is inspected (look for the variable
and surrounding logic in EastDevonDC.py, e.g., the function that builds `data`),
raise an explicit exception (e.g., ValueError or a dedicated ParsingError) with
a clear message like "Missing calendar_collection markup for EastDevonDC" so
upstream code can detect site-format changes; remove the silent `return data`
path and ensure any exception is documented or handled by the caller.
- Around line 118-120: The code currently zero-pads any user_uprn with
str(user_uprn).zfill(12) and proceeds to build the URL even for non-numeric
values; instead validate the UPRN input (variable user_uprn) is numeric and of
appropriate length before padding, and raise a clear exception (e.g.,
ValueError) on invalid input; specifically, add a guard that checks
str(user_uprn).isdigit() (and optionally length constraints) and raise if false,
then apply zfill(12) and build the URL as currently done so only valid numeric
UPRNs trigger the request.
- Around line 35-36: The fetch for the calendar page uses requests.get(url)
without timeout or status checking; update the call to use a timeout (e.g.
timeout=30) and call page.raise_for_status() before creating soup so non-200
responses aren’t parsed as valid HTML; specifically modify the requests.get(url)
call that assigns to page and add page.raise_for_status() prior to
BeautifulSoup(page.text...), mirroring the pattern used elsewhere (timeout=30
and raise_for_status()) and optionally wrap the request in a try/except to
handle RequestException.
🪄 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: 8c37b6e7-0846-425a-b3da-4a21ec11939c

📥 Commits

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

📒 Files selected for processing (1)
  • uk_bin_collection/uk_bin_collection/councils/EastDevonDC.py

Comment thread uk_bin_collection/uk_bin_collection/councils/EastDevonDC.py Outdated
Comment thread uk_bin_collection/uk_bin_collection/councils/EastDevonDC.py Outdated
Comment thread uk_bin_collection/uk_bin_collection/councils/EastDevonDC.py Outdated
Comment thread uk_bin_collection/uk_bin_collection/councils/EastDevonDC.py
@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 (4b0fe1c).

Additional details and impacted files
@@           Coverage Diff           @@
##           master    #2062   +/-   ##
=======================================
  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.

UPRN is no longer required. Uses /addressfinder endpoint to resolve
postcode to UPRN via house number/name match. Backward compatible.
@InertiaUK InertiaUK force-pushed the feat/eastdevon-postcode-lookup branch from 951c183 to b71eb9f Compare May 12, 2026 15:21
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: 1

🤖 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/uk_bin_collection/councils/EastDevonDC.py`:
- Around line 100-112: The postcode lookup currently runs even when a UPRN was
supplied and then overwrites user_uprn with a fallback; change the logic so the
postcode/addressfinder block only runs when no UPRN was provided (i.e., guard it
with a check like "if user_postcode and not user_uprn") or, alternatively, after
calling _match_address only assign to user_uprn when the original user_uprn was
falsy; update the block around user_postcode, _match_address, matched and the
assignment to user_uprn to preserve an explicitly supplied UPRN.
🪄 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: a7668374-f5a2-4e4b-940d-173bac4a0d30

📥 Commits

Reviewing files that changed from the base of the PR and between 951c183 and b71eb9f.

📒 Files selected for processing (2)
  • uk_bin_collection/tests/input.json
  • uk_bin_collection/uk_bin_collection/councils/EastDevonDC.py
🚧 Files skipped from review as they are similar to previous changes (1)
  • uk_bin_collection/tests/input.json

Comment thread uk_bin_collection/uk_bin_collection/councils/EastDevonDC.py Outdated
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