예제 #1
0
        public async Task <string> AnswerToMessage(string message)
        {
            DialogflowManager dfm = new DialogflowManager(userId, settings);

            DialogFlow.ResponseHandler responseHandler = new DialogFlow.ResponseHandler(await dfm.CheckIntent(message));
            string result = "";

            if (responseHandler.Messages != null)
            {
                foreach (string s in responseHandler.Messages)
                {
                    result += s + "\n";
                }
            }
            else
            {
                result = null;
            }
            if (responseHandler.Context.Contains("weather") && ((responseHandler.Parameters != null) && (responseHandler.Parameters.ContainsKey("city"))))
            {
                string city;
                if (responseHandler.Parameters.TryGetValue("city", out city))
                {
                    OpenWeather.OpenWeather ow = new OpenWeather.OpenWeather();
                    var wp = new WeatherParser(city, settings.OpenWeatherToken);
                    ow = await wp.GetRequest();

                    result = ow.Main.Temp.ToString("0.##");
                }
            }
            return(result);
        }
예제 #2
0
        public void Should_throw_exception_When_date_format_is_wrong()
        {
            var parser = new WeatherParser();

            var testData = GetWrongData();

            Action action = () => parser.Parse(testData);

            Assert.Throws <FormatException>(action);
        }
예제 #3
0
        private async Task <string> GetMarkdown(long chatId)
        {
            var document = await WeatherParser.GetAsync();

            if (document == null)
            {
                await this.ReplyAsync(chatId, "Информация о погоде недоступна.");

                return(string.Empty);
            }

            return(WeatherFormatter.Format(document));
        }
예제 #4
0
 private static void PrepareWeather(IEnumerable <City> сities)
 {
     foreach (City city in сities)
     {
         var args = new List <IWeather>()
         {
             new Temperature(),
             new Wind(),
             new Pressure()
         };
         var weatherParser = new WeatherParser(city);
         weatherParser.Run(args);
     }
 }
예제 #5
0
        private static void Parse()
        {
            Params.GetParams();


            using (StreamWriter sw = new StreamWriter(Directory.GetCurrentDirectory() + "\\db.db", true, System.Text.Encoding.Default, 2048))
            {
                Console.WriteLine(@"[{0}]: Начало итерации", DateTime.Now.ToString());
                if (Params.Yandex == 1)
                {
                    YandexParser.Parse(sw);
                }
                Console.Write("10%");
                if (Params.Mail == 1)
                {
                    MailParser.Parse(sw);
                }
                Console.Write("20%");
                if (Params.AccuWeather == 1)
                {
                    AccuParser.Parse(sw);
                }
                Console.Write("30%");
                if (Params.Weather == 1)
                {
                    WeatherParser.Parse(sw);
                }
                Console.Write("40%");
                if (Params.GisMeteo == 1)
                {
                    GismeteoParser.Parse(sw);
                }
                Console.Write("50%");
                if (Params.Fobos == 1)
                {
                    FobosParser.Parse(sw);
                }
                Console.Write("60%");
                if (Params.Foreca == 1)
                {
                    ForecaParser.Parse(sw);
                }
                Console.WriteLine("100%");
                Console.WriteLine(@"[{0}]: Итерация закончена", DateTime.Now.ToString());
            }
        }
예제 #6
0
        public void Should_parse_data_When_all_data_is_valid()
        {
            var parser   = new WeatherParser();
            var testData = GetTestData();

            var result = parser.Parse(testData);

            var expectedResult = new List <WeatherDto>()
            {
                new       WeatherDto()
                {
                    Date        = DateTime.Parse("3/16/2020 9:00:00 AM"),
                    Humidity    = 48,
                    Temperature = 282.7,
                    WindSpeed   = 1.2
                }
            };

            expectedResult.Should().BeEquivalentTo(result);
        }
예제 #7
0
 public String GetForecastByCityId(int id)
 {
     forecast = JsonConvert.DeserializeObject <Forecast>(Unirest.get("http://api.openweathermap.org/data/2.5/forecast?id=" + id + "&APPID=" + ApiKey + "&units=metric&lang=pl").asJson <string>().Body.ToString());
     return(WeatherParser.parseWeather(forecast));
 }
예제 #8
0
 public string GetForecastByCityName(string city)
 {
     location = city;
     forecast = JsonConvert.DeserializeObject <Forecast>(Unirest.get("http://api.openweathermap.org/data/2.5/forecast?q=" + location + "&APPID=" + ApiKey + "&units=metric&lang=pl").asJson <string>().Body.ToString());
     return(WeatherParser.parseWeather(forecast));
 }
예제 #9
0
 public String GetWeatherByPostCode(string zipCode, string countryCode)
 {
     forecast = JsonConvert.DeserializeObject <Forecast>(Unirest.get("http://api.openweathermap.org/data/2.5/forecast?zip=" + zipCode + "," + countryCode + "&APPID=" + ApiKey + "&units=metric&lang=pl").asJson <string>().Body.ToString());
     return(WeatherParser.parseWeather(forecast));
 }
예제 #10
0
 public String GetWeatherByDefaultLocation()
 {
     return(WeatherParser.parseWeather(forecast));
 }
예제 #11
0
        public string test()
        {
            Forecast forecast1 = new Forecast();

            return(WeatherParser.parseWeather(forecast1));
        }