Fix api.weather.gov/points response handling in WeatherTools (#134)
This commit is contained in:
parent
3b83ad4103
commit
8bd9ee81c0
1 changed files with 6 additions and 3 deletions
|
|
@ -42,8 +42,11 @@ public sealed class WeatherTools
|
|||
[Description("Longitude of the location.")] double longitude)
|
||||
{
|
||||
using var jsonDocument = await client.ReadJsonDocumentAsync($"/points/{latitude},{longitude}");
|
||||
var jsonElement = jsonDocument.RootElement;
|
||||
var periods = jsonElement.GetProperty("properties").GetProperty("periods").EnumerateArray();
|
||||
var forecastUrl = jsonDocument.RootElement.GetProperty("properties").GetProperty("forecast").GetString()
|
||||
?? throw new Exception($"No forecast URL provided by {client.BaseAddress}points/{latitude},{longitude}");
|
||||
|
||||
using var forecastDocument = await client.ReadJsonDocumentAsync(forecastUrl);
|
||||
var periods = forecastDocument.RootElement.GetProperty("properties").GetProperty("periods").EnumerateArray();
|
||||
|
||||
return string.Join("\n---\n", periods.Select(period => $"""
|
||||
{period.GetProperty("name").GetString()}
|
||||
|
|
@ -52,4 +55,4 @@ public sealed class WeatherTools
|
|||
Forecast: {period.GetProperty("detailedForecast").GetString()}
|
||||
"""));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue