public void Run(string city) { WeatherManager mgr; try { mgr = new WeatherManager(city); } catch (System.Net.WebException) { label2.Text = "Nie znalaziono takiego miasta."; pictureBox1.Image = null; return; } WeatherInfo weatherInfo = mgr.weatherInfo; label2.Text = $"Temperatura w {weatherInfo.Name} wynosi teraz {weatherInfo.Main.Temp - 273} st. Celcjusza. Prędkość wiatru wynosi {weatherInfo.Wind.Speed} m/s, a ciśnienie {weatherInfo.Main.Pressure} hPa."; string IconUrl = "http://openweathermap.org/img/w/" + weatherInfo.Weather[0].Icon + ".png"; string IconPath = weatherInfo.Weather[0].Icon + ".png"; var hs = new HtmlSample(IconUrl); WebClient IconClient = new WebClient(); IconClient.DownloadFile(IconUrl, IconPath); pictureBox1.ImageLocation = IconPath; }
public WeatherManager(string CityName) { City = CityName; replace_Polish_Characters(); using (var wc = new WebClient()) { Json = wc.DownloadString("http://api.openweathermap.org/data/2.5/weather?q=" + City + "&appid=7ad1f6088aa81ee7d1f348c2370adaf7"); weatherInfo = JsonConvert.DeserializeObject <WeatherInfo>(Json); } }