-
Notifications
You must be signed in to change notification settings - Fork 11
Open
Description
Hi, I read contributing readme and discussions link did not work. I know this isn't the best place for it but I am trying to return a 7-day forecast. I read docs and looked at source code. Confirming there is no way to pass a start:end timeframe. I am doing something like below now:
app.get("/wind-forecast/")
async def get_wind_forecast() -> List[Dict]:
try:
station_info = get_station_info()
start_time = datetime.now(timezone.utc).replace(microsecond=0)
end_time = start_time + timedelta(days=7)
f = getgfs.Forecast("0p25")
forecasts = []
current_time = start_time
while current_time <= end_time:
try:
result = f.get(["ugrdprs", "vgrdprs", "gustsfc"],
current_time.strftime("%Y%m%d %H:%M"),
station_info["latitude"],
station_info["longitude"])
u_wind = result.variables["ugrdprs"].data[0][0][0].item()
v_wind = result.variables["vgrdprs"].data[0][0][0].item()
gust = result.variables["gustsfc"].data[0][0][0].item()
forecasts.append({
**station_info,
"timestamp": current_time.isoformat(),
**calculate_wind_data(u_wind, v_wind, gust)
})
print(f"Data for {current_time} retrieved.")
except Exception as e:
print(f"Failed for {current_time}: {e}")
continue
current_time += timedelta(hours=3) # Get forecast every 3 hours
return forecasts
except Exception as e:
raise HTTPException(status_code=500, detail=f"Failed to fetch wind forecast: {str(e)}")
Any help would be appreciated, thank you!
Metadata
Metadata
Assignees
Labels
No labels