Skip to content

Commit 547ac4c

Browse files
authored
Fix WeatherTools to use /forecast
1 parent 62e92fa commit 547ac4c

File tree

1 file changed

+16
-7
lines changed

1 file changed

+16
-7
lines changed

samples/QuickstartWeatherServer/Tools/WeatherTools.cs

+16-7
Original file line numberDiff line numberDiff line change
@@ -41,13 +41,22 @@ public static async Task<string> GetForecast(
4141
[Description("Longitude of the location.")] double longitude)
4242
{
4343
var jsonElement = await client.GetFromJsonAsync<JsonElement>($"/points/{latitude},{longitude}");
44+
var forecastUrl = jsonElement.GetProperty("properties").GetProperty("forecast").GetString();
45+
jsonElement = await client.GetFromJsonAsync<JsonElement>(forecastUrl);
4446
var periods = jsonElement.GetProperty("properties").GetProperty("periods").EnumerateArray();
4547

46-
return string.Join("\n---\n", periods.Select(period => $"""
47-
{period.GetProperty("name").GetString()}
48-
Temperature: {period.GetProperty("temperature").GetInt32()}°F
49-
Wind: {period.GetProperty("windSpeed").GetString()} {period.GetProperty("windDirection").GetString()}
50-
Forecast: {period.GetProperty("detailedForecast").GetString()}
51-
"""));
48+
return periods.Select(period =>
49+
{
50+
return $"""
51+
Name: {period.GetProperty("name").GetString()}
52+
Start Time: {period.GetProperty("startTime").GetString()}
53+
End Time: {period.GetProperty("endTime").GetString()}
54+
Temperature: {period.GetProperty("temperature").GetInt32()}°F
55+
Wind Speed: {period.GetProperty("windSpeed").GetString()}
56+
Wind Direction: {period.GetProperty("windDirection").GetString()}
57+
Short Forecast: {period.GetProperty("shortForecast").GetString()}
58+
Detailed Forecast: {period.GetProperty("detailedForecast").GetString()}
59+
""";
60+
}).Aggregate((current, next) => current + "\n--\n" + next);
5261
}
53-
}
62+
}

0 commit comments

Comments
 (0)