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); }
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); }
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)); }
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); } }
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()); } }
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); }
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)); }
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)); }
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)); }
public String GetWeatherByDefaultLocation() { return(WeatherParser.parseWeather(forecast)); }
public string test() { Forecast forecast1 = new Forecast(); return(WeatherParser.parseWeather(forecast1)); }