public static ConditionsResults GetWeatherFor(string zipCode) { using (WebClient wc = new WebClient()) { string Json = wc.DownloadString($"http://api.wunderground.com/api/{apiKey}/conditions/q/{zipCode}.json"); var o = JObject.Parse(Json); string currentlocationJson = o["current_observation"].ToString(); var result = new ConditionsResults(); result = JsonConvert.DeserializeObject<ConditionsResults>(currentlocationJson); return result; if (!File.Exists(result.icon + ".gif")) { using (var webClient = new WebClient()) { byte[] bytes = webClient.DownloadData(result.icon_url); File.WriteAllBytes(result.icon + ".gif", bytes); } } } }
private void searchButton_Click(object sender, RoutedEventArgs e) { try { ConditionsResults Weather = new ConditionsResults(); Weather = WeatherService.GetWeatherFor(zipcodeEntryBox.Text); cityBlock.Text = Weather.Display_Location.full; latBlock.Text = "Latitude: " + Weather.Display_Location.latitude; longBlock.Text = "Longiture: " + Weather.Display_Location.longitude; elevationBlock.Text = "Elevation: " + Weather.Display_Location.elevation; weatherBlock.Text = Weather.weather; temperatureBlock.Text = "Temperature: " + Weather.temperature_string; humidityBlock.Text = "Humidity: " + Weather.relative_humidity; windBlock.Text = "Wind: " + Weather.wind_string; visibilityBlock.Text = "Visibility: " + Weather.visibility_mi; uvBlock.Text = "UV: " + Weather.UV; feelsLikeBlock.Text = "Feels like: " + Weather.feelslike_string; precepBlock.Text = "Precipitation: " + Weather.precip_today_string; lastUpdateBlock.Text = Weather.observation_time; image.Source = new BitmapImage(new Uri(Weather.icon_url)); } catch { MessageBox.Show("Please enter a valid zip code."); zipcodeEntryBox.Clear(); } }