static void Main(string[] args) { //string key = File.ReadAllText("appsettings.json"); //string APIkey = JObject.Parse(key).GetValue("DefaultKey").ToString(); //Console.WriteLine("Please enter your zipcode: "); //string zipCode = Console.ReadLine(); ////Console.WriteLine("Please enter your country code: "); ////string countryCode = Console.ReadLine().ToLower(); ////string apiCall = $"https://api.openweathermap.org/data/2.5/weather?zip={zipCode},{countryCode}&appid={APIkey}"; //string apiCall = $"https://api.openweathermap.org/data/2.5/weather?zip={zipCode}&units=imperial&appid={APIkey}"; //Console.WriteLine(); //Console.WriteLine($"It is currently {WeatherMap.GetTemp(apiCall)}°F in your location."); //Using Weather Class Object var wx = new Weather(); var cont = true; do { Console.WriteLine("Please enter your zipcode: "); string zipCode = Console.ReadLine(); wx.GetAPIResponse(zipCode); wx.GetWeather(); Console.WriteLine($"Current weather for {wx.CityName}"); Console.WriteLine($"Temperature: {wx.Temperature}°"); Console.WriteLine($"Heat Index: {wx.HeatIndex}°"); //Console.WriteLine($"Condition: {wx.Condition}"); Console.WriteLine($"Humidity: {wx.Humidity}"); Console.WriteLine($"Wind Speed: {wx.WindSpeed} mph"); Console.WriteLine(); //Thread.Sleep(5000); Console.WriteLine("Would you like to get weather for another location?"); Console.WriteLine("Y or N?"); var userResponse = Console.ReadLine().ToLower(); cont = (userResponse == "n") ? false : true; } while (cont); }
private void GetWeatherButton_Click(object sender, EventArgs e) { try { statusLabel.Text = "Fetching weather data..."; var location = new GeoLocation(); Weather.GetWeather(location.Latitude, location.Longitude); statusLabel.Text = ""; locationLabel.Text += "Today's weather in " + location.City + ":"; temperatureLabel.Text += Weather.Temperature + " °C"; descriptionLabel.Text += CultureInfo.CurrentCulture.TextInfo.ToTitleCase(Weather.Description); weatherImage.Load("https://openweathermap.org/img/w/" + Weather.ImageID + ".png"); } catch (Exception ex) { statusLabel.Text = ex.Message; } }
private void Form1_Load(object sender, EventArgs e) { Querry = "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid = 516922 and u='c' &format=json"; QuerryKrosno = "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid = 502438 and u='c' &format=json"; QuerryJaslo = "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid = 497151 and u='c' &format=json"; QuerryPrzemysl = "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid = 514387 and u='c' &format=json"; QuerrySanok = "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid = 517369 and u='c' &format=json"; QuerrySacz = "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid = 509923 and u='c' &format=json"; QuerrySvidnik = "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid = 509923 and u='c' &format=json"; QuerryDukla = "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid = 492348 and u='c' &format=json"; QuerryBrzozow = "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid = 488211 and u='c' &format=json"; QuerryStrzyzow = "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid = 520664 and u='c' &format=json"; QuerryRzeszow = "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid = 517126 and u='c' &format=json"; QuerryGorlice = "https://query.yahooapis.com/v1/public/yql?q=select * from weather.forecast where woeid = 494420 and u='c' &format=json"; var Generalforecast = info.GetWeather(Querry); var GeneralforecastKrosno = info.GetWeather(QuerryKrosno); var GeneralforecastJaslo = info.GetWeather(QuerryJaslo); var GeneralforecastPrzemysl = info.GetWeather(QuerryPrzemysl); var GeneralforecastSanok = info.GetWeather(QuerrySanok); var GeneralforecastSacz = info.GetWeather(QuerrySacz); var GeneralforecastSvidnik = info.GetWeather(QuerrySvidnik); var GeneralforecastDukla = info.GetWeather(QuerryDukla); var GeneralforecastBrzozow = info.GetWeather(QuerryBrzozow); var GeneralforecastStrzyzow = info.GetWeather(QuerryStrzyzow); var GeneralforecastRzeszow = info.GetWeather(QuerryRzeszow); var GeneralforecastGorlice = info.GetWeather(QuerryGorlice); var Windforecast = info.GetWeatherWind(Querry); var Atmosphereforecast = info.GetWeatherAtmosphere(Querry); var AstronomyTime = info.GetAstrononyTime(Querry); var Forecast = info.GetForecast(Querry); City.Text = "Rymanów"; Local.Text = "Aktualna Prognoza"; label1.Text = Generalforecast.text; label2.Text = Generalforecast.temp + " C"; label3.Text = Windforecast.speed + " km/h"; label4.Text = Atmosphereforecast.humidity + " %"; label11.Text = AstronomyTime.sunrise; label12.Text = AstronomyTime.sunset; Day1.Text = Forecast[0].day; Day2.Text = Forecast[1].day; Day3.Text = Forecast[2].day; Day4.Text = Forecast[3].day; Day5.Text = Forecast[4].day; temp1.Text = Forecast[0].high + " C"; temp2.Text = Forecast[1].high + " C"; temp3.Text = Forecast[2].high + " C"; temp4.Text = Forecast[3].high + " C"; temp5.Text = Forecast[4].high + " C"; con1.Text = Forecast[0].text; con2.Text = Forecast[1].text; con3.Text = Forecast[2].text; con4.Text = Forecast[3].text; con5.Text = Forecast[4].text; mapl_c.Text = Generalforecast.temp + " C"; mapl1_c.Text = GeneralforecastKrosno.temp + " C"; mapl2_c.Text = GeneralforecastJaslo.temp + " C"; mapl3_c.Text = GeneralforecastPrzemysl.temp + " C"; mapl4_c.Text = GeneralforecastSanok.temp + " C"; mapl5_c.Text = GeneralforecastSacz.temp + " C"; mapl6_c.Text = GeneralforecastSvidnik.temp + " C"; mapl7_c.Text = GeneralforecastDukla.temp + " C"; mapl8_c.Text = GeneralforecastBrzozow.temp + " C"; mapl9_c.Text = GeneralforecastStrzyzow.temp + " C"; mapl10_c.Text = GeneralforecastRzeszow.temp + " C"; mapl11_c.Text = GeneralforecastGorlice.temp + " C"; mapl.Text = Generalforecast.text; mapl1.Text = GeneralforecastKrosno.text; mapl2.Text = GeneralforecastJaslo.text; mapl3.Text = GeneralforecastPrzemysl.text; mapl4.Text = GeneralforecastSanok.text; mapl5.Text = GeneralforecastSacz.text; mapl6.Text = GeneralforecastSvidnik.text; mapl7.Text = GeneralforecastDukla.text; mapl8.Text = GeneralforecastBrzozow.text; mapl9.Text = GeneralforecastStrzyzow.text; mapl10.Text = GeneralforecastRzeszow.text; mapl11.Text = GeneralforecastGorlice.text; SetUp(); }
private void GeoDetect() { if (coordinate == null) { label16.Text = "Status: device geodata definition..."; label16.ForeColor = Color.Gray; } int seconds = 10; int step = progressBar1.Maximum / seconds; for (int i = 0; i < seconds; i++) { if (geoDetected == false) { if (watcher.Status == GeoPositionStatus.Ready && !watcher.Position.Location.IsUnknown) { coordinate = watcher.Position.Location; openWeatherOneAPI = weather.GetWeather(coordinate); if (InvokeRequired) { Invoke(new Action(() => SetParameters())); } else { SetParameters(); } geoDetected = true; break; } } if (InvokeRequired) { Invoke(new Action(() => ProgressBar_Change(i * step))); } else { ProgressBar_Change(i * step); } Thread.Sleep(1000); } if (geoDetected == false) { MessageBox.Show("Failed to determine your device’s location.\n" + "Please select a city yourself."); if (label16.InvokeRequired) { label16.Invoke(new Action(() => { label16.Text = "Status: device geodata not defined."; label16.ForeColor = Color.Red; })); } else { label16.Text = "Status: device geodata not defined."; label16.ForeColor = Color.Red; } } if (comboBox1.InvokeRequired) { comboBox1.Invoke(new Action(() => comboBox1.Enabled = true)); } else { comboBox1.Enabled = true; } if (progressBar1.InvokeRequired) { progressBar1.Invoke(new Action(() => progressBar1.Value = 0)); } else { progressBar1.Value = 0; } }