Skip to content

Commit a39d108

Browse files
committed
Harden Met Office datastream fallback
1 parent 08cc7d7 commit a39d108

1 file changed

Lines changed: 11 additions & 0 deletions

File tree

publishers/met_office_datahub/met_office_datahub_publisher.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -412,6 +412,17 @@ def _raw_datastream_ids(self, sys_id: str) -> dict[str, str]:
412412
elif key == "outputName" and current_id:
413413
station_ds[value] = current_id
414414
current_id = None
415+
for offset in range(0, 25):
416+
page_url = f"{self._base_url}/systems/{sys_id}/datastreams?limit=1&offset={offset}"
417+
try:
418+
with urlopen(Request(page_url, headers=headers), timeout=30, context=ctx) as resp:
419+
page_text = resp.read().decode()
420+
except Exception:
421+
continue
422+
page_id = re.search(r'"id"\s*:\s*"([^"]+)"', page_text)
423+
page_output = re.search(r'"outputName"\s*:\s*"([^"]+)"', page_text)
424+
if page_id and page_output:
425+
station_ds[page_output.group(1)] = page_id.group(1)
415426
return station_ds
416427

417428
def connect(self):

0 commit comments

Comments
 (0)