mirror of
https://git.ianrenton.com/ian/spothole.git
synced 2026-04-30 02:35:57 +00:00
Add fetching of NOAA 3-day forecast
This commit is contained in:
@@ -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]
|
||||
|
||||
Reference in New Issue
Block a user