Skip to content

Fix STF (Staffordshire Moorlands) scraper#411

Open
symroe wants to merge 1 commit into
masterfrom
fix/STF-scraper
Open

Fix STF (Staffordshire Moorlands) scraper#411
symroe wants to merge 1 commit into
masterfrom
fix/STF-scraper

Conversation

@symroe

@symroe symroe commented Jul 2, 2026

Copy link
Copy Markdown
Member

What broke

The scraper filters councillors by email domain, keeping only those with a staffsmoorlands.gov.uk address. Councillor ID 1414 is a known exception (no email listed). On June 30 a second councillor appeared in the ModGov XML without an email attribute set on the CouncillorBase object.

The guard at line 8 (if not getattr(councillor, "email", None)) correctly detected the missing email, but the block only returned early for ID 1414. Any other emailless councillor fell through to line 12 (if "staffsmoorlands.gov.uk" in councillor.email:) which raised AttributeError: 'CouncillorBase' object has no attribute 'email', crashing the entire run.

What was fixed

  • Added raise SkipCouncillorException() as the else-branch inside the if not getattr(councillor, "email", None): block, so any councillor without an email who is not the known exception (ID 1414) is silently skipped rather than crashing the run.

Scrape results

The ModGov endpoint returns 403 from this environment so exact counts require a Lambda run. Based on the XML structure (ModGov GetCouncillorsByWard), the council has 56 seats; the scraper previously ran successfully with ~56 councillors.

Metric Count
Councillors found TBC (Lambda run needed; ~56 expected, minus any without staffsmoorlands.gov.uk email)
With email address TBC
With photo TBC

Generated by Claude Code

… not ID 1414

The scraper filters to only include councillors with a staffsmoorlands.gov.uk
email address, with a special exception for councillor ID 1414 who is known
to have no email listed.

The bug: when a councillor (other than 1414) has no email attribute, the
guard block entered via `if not getattr(councillor, "email", None)` only
returned early for ID 1414 — all other emailless councillors fell through
to `if "staffsmoorlands.gov.uk" in councillor.email:` which raised
AttributeError because the attribute is absent, not None.

Fix: add `raise SkipCouncillorException()` as the else-branch so that any
councillor without an email (and not the known exception 1414) is silently
skipped rather than crashing the entire run.
@symroe

symroe commented Jul 2, 2026

Copy link
Copy Markdown
Member Author

Re-scrape after 91c500f

Initial push: added raise SkipCouncillorException() in the no-email / non-1414 branch to prevent AttributeError crashing the run.

The ModGov endpoint (democracy.staffsmoorlands.gov.uk) returns 403 from this environment so a full scrape cannot be run pre-merge. The logic change is straightforward: councillors with no email and not the known exception (ID 1414) are now silently skipped rather than causing an unhandled AttributeError that aborts the entire run.

Metric Count
Councillors found TBC (Lambda run needed; ~56 expected minus any non-staffsmoorlands emails)
With email address TBC
With photo TBC

Counts will be updated here after the next Lambda run confirms the fix.


Generated by Claude Code

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