Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,6 @@ resources:
- name: data_version
default: dev
- name: years
default: "[202324]"
default: "[202324, 202425]"
- name: projection_year
default: "2022"
7 changes: 4 additions & 3 deletions src/nhp/data/population_projections/get_ons_files_2022.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,16 @@ def get_snpp_uris(path: str) -> list[str]:
matches = soup.find_all(
"a",
attrs={
"aria-label": lambda x: (
"aria-label": lambda x: bool(
x
and "2022-based" in x
and re.match("^Download (Population|Birth) projections", x)
)
},
)

return [urljoin(ONS_URL, i["href"]) for i in matches] # ty: ignore[invalid-argument-type]
hrefs = [i.get("href") for i in matches]
return [urljoin(ONS_URL, href) for href in hrefs if isinstance(href, str)]


def snpp_uri_variant_match(uri: str) -> str | None:
Expand Down Expand Up @@ -173,7 +174,7 @@ def get_npp_uri(path: str) -> str:
pattern = "Download Zipped population projections data files, .*: 2022 based in zip format"
match = soup.find(
"a",
attrs={"aria-label": lambda x: x and re.match(pattern, x)},
attrs={"aria-label": lambda x: bool(x and re.match(pattern, x))},
)
assert match is not None, "could not find NPP zip file link"
assert isinstance(match["href"], str), "unexpected href type for NPP zip file link"
Expand Down
Loading