File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed
Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -1502,8 +1502,8 @@ public static class WeatherTools
15021502 HttpClient client ,
15031503 [Description (" The US state to get alerts for." )] string state )
15041504 {
1505- var jsonElement = await client .GetFromJsonAsync <JsonElement >($" /alerts/active/area/{state }" );
1506- var alerts = jsonElement .GetProperty (" features" ).EnumerateArray ();
1505+ var stateData = await client .GetFromJsonAsync <JsonElement >($" /alerts/active/area/{state }" );
1506+ var alerts = stateData .GetProperty (" features" ).EnumerateArray ();
15071507
15081508 if (! alerts .Any ())
15091509 {
@@ -1529,8 +1529,16 @@ public static class WeatherTools
15291529 [Description (" Latitude of the location." )] double latitude ,
15301530 [Description (" Longitude of the location." )] double longitude )
15311531 {
1532- var jsonElement = await client .GetFromJsonAsync <JsonElement >($" /points/{latitude },{longitude }" );
1533- var periods = jsonElement .GetProperty (" properties" ).GetProperty (" periods" ).EnumerateArray ();
1532+ var pointData = await client .GetFromJsonAsync <JsonElement >($" /points/{latitude },{longitude }" );
1533+ var forecastUrl = pointData .GetProperty (" properties" ).GetProperty (" forecast" ).GetString ();
1534+
1535+ if (string .IsNullOrEmpty (forecastUrl ))
1536+ {
1537+ return " Forecast URL not found." ;
1538+ }
1539+
1540+ var forecastData = await client .GetFromJsonAsync <JsonElement >(forecastUrl );
1541+ var periods = forecastData .GetProperty (" properties" ).GetProperty (" periods" ).EnumerateArray ();
15341542
15351543 return string .Join (" \n ---\n " , periods .Select (period => $"""
15361544 {period .GetProperty (" name" ).GetString ()}
You can’t perform that action at this time.
0 commit comments