Add fetching of NOAA 3-day forecast

This commit is contained in:
Ian Renton
2026-04-03 18:11:45 +01:00
parent 4a6d9da031
commit c10b5e4947
11 changed files with 96 additions and 70 deletions

View File

@@ -4,7 +4,7 @@ from datetime import datetime, timezone
from solarconditionsproviders.http_solar_conditions_provider import HTTPSolarConditionsProvider
POLL_INTERVAL = 3600
POLL_INTERVAL = 10800 # Every 3 hours
URL = "https://services.swpc.noaa.gov/text/3-day-forecast.txt"
@@ -132,17 +132,16 @@ class NOAA3dayForecast(HTTPSolarConditionsProvider):
continue
start_hour = int(time_match.group(1))
raw_values = time_match.group(3).split()
# Split on 2 or more spaces so that e.g. "5.67 (G2)" stays as one token per column
raw_values = re.split(r' {2,}', time_match.group(3).strip())
for i, val in enumerate(raw_values):
if i >= len(column_dates):
break
# Discard bracketed values
if val.startswith('(') and val.endswith(')'):
continue
# Take only the leading numeric part, discarding any bracketed section
try:
kp = float(val)
except ValueError:
kp = float(val.split()[0])
except (ValueError, IndexError):
continue
date = column_dates[i]