public void UpdateWeatherData() { try { //If no settings, do nothing if (string.IsNullOrEmpty(_citySetting.Value) || string.IsNullOrEmpty(_unitOfMeasurementSetting.Value)) return; //TODO: Use settings string accessKey = _apiKeySetting.Value; WeatherClient client = new WeatherClient(accessKey); CurrrentWeatherModel data = client.GetCurrentWeatherAsync<CurrrentWeatherModel>(_citySetting.Value, "en", _unitOfMeasurementSetting.Value).Result; // Weather Measurements DataModel.Weather = (WeatherConditions)Enum.Parse(typeof(WeatherConditions), data.Weather.FirstOrDefault().Main); DataModel.Temp = data.Main.Temp; DataModel.FeelsLike = data.Main.FeelsLike; DataModel.TempMin = data.Main.TempMin; DataModel.TempMax = data.Main.TempMax; DataModel.Pressure = data.Main.Pressure; DataModel.Humidity = data.Main.Humidity; // Visibility DataModel.Clouds = data.Clouds.All; // Cloudiness DataModel.Visibility = data.Visibility; // Meters // Sunrise Sunset DataModel.Sunrise = DateTimeOffset.FromUnixTimeSeconds(data.Sys.Sunrise).DateTime.ToLocalTime(); // unix, UTC DataModel.Sunset = DateTimeOffset.FromUnixTimeSeconds(data.Sys.Sunset).DateTime.ToLocalTime(); // unix, UTC // unix, UTC // Wind DataModel.Wind.Speed = data.Wind.Speed; DataModel.Wind.Deg = data.Wind.Deg; DataModel.Wind.WindDirection = (WindDirectionCodes)Enum.Parse(typeof(WindDirectionCodes), data.Wind.WindDirection); } catch (Exception e) { _logger.Error(e.ToString()); } }
public void GetCurrentWeatherTest() { List <string> cities = new List <string>() { "Canberra", "Brussels", "Beijing", "London", "Moscow", "Prague", "Tallinn", "Helsinki", "Paris", "Berlin", "Reykjavik" }; WeatherClient client = new WeatherClient(AccessKey); foreach (string city in cities) { CurrrentWeatherModel data = client.GetCurrentWeatherAsync <CurrrentWeatherModel>(city, "en").Result; } }