Beispiel #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            try
            {
                city    = input.Text;
                results = client.Query(city);

                outputF.Text  = results.Main.Temperature.FahrenheitCurrent.ToString();
                outputC.Text  = Convert.ToString(Formula(results.Main.Temperature.FahrenheitCurrent));
                timer.Enabled = true;

                var city    = input.Text;
                var results = client.Query(city);

                Console.WriteLine($"Температура в {city}  {results.Main.Temperature.FahrenheitCurrent}F.");
                output.Text = results.Main.Temperature.FahrenheitCurrent.ToString();
                SystemSounds.Beep.Play();
            }
            catch (Exception ex)
            {
                if (input.Text == "")
                {
                    MessageBox.Show("Вы не ввели свой город.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
                else
                {
                    MessageBox.Show($"У вас произошла ошибка №{ex.HResult}Обратитесь к администратору для исправления данной ошибки.", "Ошибка!", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
        }
Beispiel #2
0
        public WeatherInfo GetWeatherInfo(string city)
        {
            try
            {
                if (client == null)
                {
                    // can be some exception in static constructor or for example by time out
                    ClientInitialization();
                }

                var results = client.Query(city);

                WeatherInfo weatherInfo = new WeatherInfo
                {
                    Temperature = results.Main.Temperature.CelsiusCurrent,
                    Humidity    = results.Main.Humdity,
                    Pressure    = results.Main.Pressure,
                    City        = city
                };

                return(weatherInfo);
            }
            catch (Exception e)
            {
                throw new OpenWeatherAPIException("Can't get result at that time by connection to OpenWeatherMap", e);
            }
        }
Beispiel #3
0
        public void GetWeather(string city)
        {
            WeatherConditions weatherConditions = new WeatherConditions();

            var client = new OpenWeatherAPI.OpenWeatherAPI("d9a69d574ef7c5bdccdc52b2b0b13458");

            var results = client.Query(city);

            if (client != null)
            {
                weatherConditions.CurentTemperature        = results.Main.Temperature.CelsiusCurrent;
                weatherConditions.Direction                = results.Wind.Direction;
                weatherConditions.MaxTemperature           = results.Main.Temperature.CelsiusMaximum;
                weatherConditions.MinTemperature           = results.Main.Temperature.CelsiusMaximum;
                weatherConditions.SeaLevel                 = results.Main.SeaLevelAtm;
                weatherConditions.WindSpeedMetersPerSecond = results.Wind.SpeedMetersPerSecond;
                //weatherConditions.RainLevel = results.Rain.H3;
                weatherConditions.Degri = results.Wind.Degree;
                weatherConditionsOld    = weatherConditions;
                weatherConditions.Cyti  = city;
                countGet += 1;
                weatherConditions.CountCondition = countGet;
                EventNewWeatherConditions(weatherConditions);
            }
        }
Beispiel #4
0
        static void Main(string[] args)
        {
            var client = new OpenWeatherAPI.OpenWeatherAPI("6ac232d2dac00bdaa191f6d3db9cbeec");

            SpeechSynthesizer synthesizer = new SpeechSynthesizer();

            synthesizer.SelectVoiceByHints(VoiceGender.Female);
            Environment.SetEnvironmentVariable("GOOGLE_APPLICATION_CREDENTIALS", "C:\\Users\\Mi'Angel\\Downloads\\Genesis-1ac8c357b5fb.json");

            synthesizer.Speak("Hello. I'm Genesis.");
            StreamingMicRecognizeAsync(2).Wait();
            Console.WriteLine(speechResult);

            if (speechResult.Contains("weather"))
            {
                // Get location

                var city = "Phoenix, Arizona";
                //Get API result
                //To get tomorrow or yesterdays weather or a forecast, we can use a switch statement to return a result
                //as a subContains if speech aslo contains today, tomorrow



                synthesizer.Speak($"Fetching weather data for '{city}'");
                var results = client.Query(city);

                synthesizer.Speak($"The temperature in {city} is {results.Main.Temperature.FahrenheitCurrent} degrees. There is {results.Wind.SpeedFeetPerSecond.ToString("0")} feet per second wind in the {results.Wind.Direction} direction.");
            }
        }
Beispiel #5
0
        public IActionResult Index()
        {
            var client = new OpenWeatherAPI.OpenWeatherAPI("7b678f7b3998ff5249745148d5c8a38a");

            var results = client.Query("London");

            return(View(results));
        }
Beispiel #6
0
        public IActionResult Index(string city)
        {
            var client = new OpenWeatherAPI.OpenWeatherAPI("7b678f7b3998ff5249745148d5c8a38a");

            try
            {
                if (city == null)
                {
                    city = "London";
                }
                var results = client.Query(city);
                return(View(results));
            }
            catch (Exception ex)
            {
                return(View(ex.Message));
            }
        }
        static void Main(string[] args)
        {
            var client = new OpenWeatherAPI.OpenWeatherAPI("YOUR-API-KEY");

            Console.WriteLine("OpenWeatherAPI Example Application");
            Console.WriteLine();

            Console.WriteLine("Enter city to get weather data for:");
            var city = Console.ReadLine();

            Console.WriteLine();

            Console.WriteLine($"Fetching weather data for '{city}'");
            var results = client.Query(city);

            Console.WriteLine($"The temperature in {city} is {results.Main.Temperature.FahrenheitCurrent}F. There is {results.Wind.SpeedFeetPerSecond} f/s wind in the {results.Wind.Direction} direction.");

            Console.ReadLine();
        }