File tree 1 file changed +16
-7
lines changed
samples/QuickstartWeatherServer/Tools
1 file changed +16
-7
lines changed Original file line number Diff line number Diff line change @@ -41,13 +41,22 @@ public static async Task<string> GetForecast(
41
41
[ Description ( "Longitude of the location." ) ] double longitude )
42
42
{
43
43
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 ) ;
44
46
var periods = jsonElement . GetProperty ( "properties" ) . GetProperty ( "periods" ) . EnumerateArray ( ) ;
45
47
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 ) ;
52
61
}
53
- }
62
+ }
You can’t perform that action at this time.
0 commit comments