コード例 #1
0
        /// <summary>
        /// Отправить ответ погоды
        /// </summary>
        /// <param name="coords">Координаты</param>
        /// <param name="chat">Чат ИД</param>
        /// <returns>True False</returns>
        public static bool SendWeatherAnswer(WeatherLocationModel coords, ChatId chat = null)
        {
            var    keyboard = KeyboardCore.ConfigureStandartKeyboard();
            string result   = WebApiCore.ExecuteHttpRequest(WeatherCore.CreateApiStringWithLocation(new Location()
            {
                Latitude  = coords.lat,
                Longitude = coords.lon
            }));
            GeoWeatherModel model = JsonConvert.DeserializeObject <GeoWeatherModel>(result);

            if (model is null)
            {
                SendBadWeatherResponse(chat);
            }
            WithKeyboardSending(CreateWeatherAnswer(model), keyboard, chat: chat);
            return(false);
        }
コード例 #2
0
        private static string CreateWeatherAnswer(GeoWeatherModel model)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendLine(localization.Current.WeatherResultStart);
            sb.AppendLine($"{localization.Current.WeatherResultPlace}: {model.location.region}");
            sb.AppendLine($"{localization.Current.WeatherResultOnStreet}: {model.current.condition.text}");
            sb.AppendLine($"{localization.Current.WeatherResultTemperature}: " +
                          $"{model.current.temp_c} {localization.Current.WeatherResultGradus}, " +
                          $"{model.current.temp_f} {localization.Current.WeatherResultFarengeit}");
            sb.AppendLine($"{localization.Current.WeatherResultFeelsLike}: " +
                          $"{model.current.feelslike_c} {localization.Current.WeatherResultGradus}, " +
                          $"{model.current.feelslike_f} {localization.Current.WeatherResultFarengeit}");
            sb.AppendLine($"{localization.Current.WeatherResultWindDescription}: " +
                          $"{model.current.wind_kph} {localization.Current.WeatherResultKMHour}, " +
                          $"{model.current.wind_mph} {localization.Current.WeatherResultMeterSecond}");
            return(sb.ToString());
        }