using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; using Microsoft.Extensions.Hosting; using System.Net.Http.Json; using WeatherDashboard; var builder = Host.CreateDefaultBuilder(args); builder.ConfigureAppConfiguration((context, config) => { var environment = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT"); config.AddEnvironmentVariables(); config.AddJsonFile("appsettings.json"); config.AddJsonFile($"appsettings.{environment}.json", true); }); builder.ConfigureServices(services => { services.AddHttpClient(); }); var app = builder.Build(); var configuration = app.Services.GetService(); var httpClientFactory = app.Services.GetService(); var httpClient = httpClientFactory.CreateClient(); var apiUrl = configuration["ApiUrl"]; var gotifyUrl = configuration["GotifyUrl"]; var weatherSet = await httpClient.GetFromJsonAsync(apiUrl); var todaysForecast = weatherSet.Forecast.FirstOrDefault().Summary; var notificationResponse = await httpClient.PostAsJsonAsync(gotifyUrl, new { title = "Weather Conditions", message = $"Today: {todaysForecast.ConditionName} with a high of {todaysForecast.HighTemp} and a low of {todaysForecast.LowTemp}. Currently: {weatherSet.Current.ConditionName} and {weatherSet.Current.Temperature} degrees.", priority = 5 });