예제 #1
0
        public static void ftg()
        {
            do
            {
                if (!open1)
                {
                    Console.WriteLine("search meteo");

                    Thread.Sleep(0);
                    Application.DoEvents();
                    open1 = true;
                    try
                    {
                        url1 = "http://api.openweathermap.org/data/2.5/weather?q=saguenay&appid=dfbd9862a903062c9442bd69db905961&units=metric&lang=fr";
                        json = clientd.GetStringAsync(url1).Result;


                        cWeather wea = JsonConvert.DeserializeObject <cWeather>(json);
                        Console.WriteLine("saguenay");

                        Console.WriteLine(Convert.ToString(wea.main.temp) + " °C");

                        Console.WriteLine(Convert.ToString(wea.main.humidity) + " %");

                        Console.WriteLine(Convert.ToString(wea.main.pressure) + " hpa");

                        Console.WriteLine(Convert.ToString(wea.wind.speed + " m/s"));

                        Console.WriteLine(Convert.ToString(wea.weather.ElementAt(0).description));

                        url2 = "http://openweathermap.org/img/w/" + Convert.ToString(wea.weather.ElementAt(0).icon + ".png");


                        sayt("la temperature pour saguenay est de " + wea.main.temp + " °C" + " et lhumidity " + wea.main.humidity + " %");
                    }
                    catch {
                        Console.WriteLine("error 1");
                    }

                    open1 = true;
                }
                else
                {
                    Console.WriteLine("searching");

                    Thread.Sleep(0);
                    Application.DoEvents();
                    open1 = false;
                    try
                    {
                        Class5 lm = new Class5();
                        lm.GetWeather();
                    }
                    catch {
                        Console.WriteLine("error 2");
                    }

                    open1 = false;
                }

                Application.DoEvents();

                Thread.Sleep(1200000);
                Console.WriteLine("sleep done");
            } while (true);
        }