Esempio n. 1
0
        public void Answer(Message message)
        {
            string city = "Rome";

            try
            {
                substr = message.text.Substring(14);
                city   = substr;
                string         url            = ($"https://api.openweathermap.org/data/2.5/weather?q={city}&units=metric&appid=01919e822c17cd48130238904353d786");
                HttpWebRequest httpWebRequest = (HttpWebRequest)WebRequest.Create(url);

                HttpWebResponse httpWebResponse = (HttpWebResponse)httpWebRequest.GetResponse();

                string response;

                using (StreamReader streamReader = new StreamReader(httpWebResponse.GetResponseStream()))
                {
                    response = streamReader.ReadToEnd();
                }


                WeatherResponse weatherResponse         = JsonConvert.DeserializeObject <WeatherResponse>(response);
                float           curweatherweatherfloat  = weatherResponse.Main.Temp;
                string          curweatherstr           = curweatherweatherfloat.ToString();
                float           curweatherweather1float = weatherResponse.Main.Feels_like;
                string          curweatherstr1          = curweatherweather1float.ToString();
                int             humidity      = weatherResponse.Main.Humidity;
                string          humiditystr   = humidity.ToString();
                float           curwindfloat  = weatherResponse.Wind.Speed;
                string          curwindstr    = curwindfloat.ToString();
                int             pressure      = weatherResponse.Main.Pressure;
                int             pressure1     = (int)(pressure / 1.333);
                string          pressurestr   = pressure1.ToString();
                int             clouds        = weatherResponse.Clouds.All;
                string          cloudsstr     = clouds.ToString();
                int             visibility    = weatherResponse.Visibility;
                string          visibilitystr = visibility.ToString();



                publish.SendMessage($"Здравствуйте!\nТемпература в городе {curweatherstr} °C.\nТемпература ощущается как {curweatherstr1} °C.\nВлажность {humiditystr} %.\nДавление {pressurestr} мм рт. ст.\nСкорость ветра {curwindstr} м/c.\nОблачность {cloudsstr} %.\nВидимость {visibilitystr} метров.", message.chat.id);
            }
            catch
            {
                publish.SendMessage("Неверный формат запроса о погоде в данном городе или ошибка в названии города", message.chat.id);
            }
        }
Esempio n. 2
0
        public void Answer(Message message)
        {
            string city3 = "Rome";

            try
            {
                substr3 = message.text.Substring(26);
                city3   = substr3;
                string         url1            = ($"https://api.openweathermap.org/data/2.5/weather?q={city3}&units=metric&appid=01919e822c17cd48130238904353d786");
                HttpWebRequest httpWebRequest3 = (HttpWebRequest)WebRequest.Create(url1);

                HttpWebResponse httpWebResponse3 = (HttpWebResponse)httpWebRequest3.GetResponse();

                string response3;

                using (StreamReader streamReader3 = new StreamReader(httpWebResponse3.GetResponseStream()))
                {
                    response3 = streamReader3.ReadToEnd();
                }


                WeatherResponse weatherResponse3 = JsonConvert.DeserializeObject <WeatherResponse>(response3);
                float           timezone         = weatherResponse3.Timezone;
                float           timezone1        = timezone / 3600;
                var             timezone2        = (double)timezone1;
                string          timezone1str     = timezone1.ToString();


                DateTime time      = DateTime.UtcNow;
                var      time2     = time.AddHours(timezone2);
                string   asString  = time2.ToString();
                string   asString2 = time2.ToString("dd.MM.yyyy, hh:mm:ss tt", CultureInfo.InvariantCulture);



                publish.SendMessage(asString, message.chat.id);
                publish.SendMessage(asString2, message.chat.id);
            }
            catch
            {
                publish.SendMessage("Неверный формат запроса о погоде в данном городе или ошибка в названии города", message.chat.id);
            }
        }