Accept official Statbel geometry date format
This commit is contained in:
@@ -59,6 +59,7 @@ GEOMETRY_MEMBER_PATTERN = re.compile(
|
||||
r"^sh_statbel_statistical_sectors_(?:31370_)?(20[0-9]{2})0101\.geojson$",
|
||||
re.IGNORECASE,
|
||||
)
|
||||
GEOMETRY_DATE_PATTERN = re.compile(r"^(20[0-9]{2})([-/])([0-9]{2})\2([0-9]{2})$")
|
||||
POPULATION_SOURCE_PATTERN = re.compile(
|
||||
r"^/sites/default/files/files/opendata/bevolking/sectoren/"
|
||||
r"OPENDATA_SECTOREN_(20[0-9]{2})(?:_(NEW|OLD))?\.zip$",
|
||||
@@ -123,6 +124,18 @@ def _layout_from_variant(variant: str | None) -> str:
|
||||
return variant.lower()
|
||||
|
||||
|
||||
def _normalize_geometry_date(value: Any) -> str | None:
|
||||
raw_value = str(value or "").strip()
|
||||
match = GEOMETRY_DATE_PATTERN.fullmatch(raw_value)
|
||||
if not match:
|
||||
return None
|
||||
normalized = f"{match.group(1)}-{match.group(3)}-{match.group(4)}"
|
||||
try:
|
||||
return datetime.strptime(normalized, "%Y-%m-%d").date().isoformat()
|
||||
except ValueError:
|
||||
return None
|
||||
|
||||
|
||||
def _validate_source_url(url: str, pattern: re.Pattern[str], *, code: str) -> re.Match[str]:
|
||||
parsed = urlsplit(url)
|
||||
match = pattern.fullmatch(parsed.path)
|
||||
@@ -428,7 +441,7 @@ def parse_geometry_archive(content: bytes, year: int) -> GeometryArchiveData:
|
||||
"Geometry artifact contains duplicate sector codes.",
|
||||
sector_code=sector_code,
|
||||
)
|
||||
if str(properties.get("dt_situation") or "") != expected_date:
|
||||
if _normalize_geometry_date(properties.get("dt_situation")) != expected_date:
|
||||
_fail(
|
||||
"STATBEL_GEOMETRY_DATE_MISMATCH",
|
||||
"Geometry situation date does not match the population reference year.",
|
||||
|
||||
Reference in New Issue
Block a user