File tree Expand file tree Collapse file tree
samples/QuickstartWeatherServer/Tools Expand file tree Collapse file tree Original file line number Diff line number Diff 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+ }
You can’t perform that action at this time.
0 commit comments