public static async Task Run([TimerTrigger("%CRON_EXPRESSION%")] TimerInfo myTimer, TraceWriter log) { log.Info($"FetchAndPostForecast function executed at: {DateTime.UtcNow}"); var forecastService = new YrForecastService(); var textualForecast = await forecastService.GetTextualForecast(YrLocationId); log.Info($"FetchAndPostForecast got forecast: {textualForecast}"); var fullForecast = await forecastService.GetFullForecast(YrLocationId); var slackMessage = new ForecastParser().CreateSlackMessage(textualForecast, fullForecast); log.Info($"Sending Slack message:\n{slackMessage}"); var response = await HttpClient.PostAsJsonAsync(SlackWebhookUrl, new SlackMessage { Text = slackMessage }); if (response.IsSuccessStatusCode) { log.Info("Message successfully sent to Slack webhook"); } else { log.Error(response.StatusCode.ToString()); log.Error(response.ReasonPhrase); if (response.Content != null) { log.Error(await response.Content.ReadAsStringAsync()); } } }
public void OnForecastAPILoadCompleted(String result) { Debug.WriteLine(">>>>> ScheduledAgent OnInvoke :: OnForecastAPILoadCompleted :: " + result.Length); if (String.IsNullOrEmpty(result)) { // 取資料錯誤,不更新了 NotifyComplete(); } else { TileService.Instance.mAreaWeatherList.Clear(); Dictionary <String, List <RichListItem> > allForecast = ForecastParser.ParseAllForecast(result); if (allForecast != null && allForecast.Count > 0) { TileService.Instance.mAreaWeatherList = allForecast; Deployment.Current.Dispatcher.BeginInvoke(() => { TileService.Instance.RefreshAllTile(); } ); } NotifyComplete(); //ScheduledActionService.LaunchForTest(Constants.TWWEATHER_BACKGROUND_SCHEDULER, TimeSpan.FromMilliseconds(15000)); } }
public void TestSevenForecast() { List <Forecast> forecasts = ForecastParser.Parse("1. 1:1<br />2. 0:0<br />4. 0:0<br />5. 1:1<br />6. 1:0<br />7. 0:0<br />8. 0:0<br /><p style='margin: 0.7em 0 0.2em 0'><font size='-2'>(<a href='http://community.livejournal.com/ru_football/7192133.html?replyto=424263749'>Reply to this</a>) </font></p>", new Ljuser()).ToList(); Assert.Equal(7, forecasts.Count); Assert.Equal(1, forecasts[0].Number); Assert.Equal(1, forecasts[0].OwnersGoals); Assert.Equal(1, forecasts[0].GuestsGoals); Assert.Equal(2, forecasts[1].Number); Assert.Equal(0, forecasts[1].OwnersGoals); Assert.Equal(0, forecasts[1].GuestsGoals); Assert.Equal(4, forecasts[2].Number); Assert.Equal(0, forecasts[2].OwnersGoals); Assert.Equal(0, forecasts[2].GuestsGoals); Assert.Equal(5, forecasts[3].Number); Assert.Equal(1, forecasts[3].OwnersGoals); Assert.Equal(1, forecasts[3].GuestsGoals); Assert.Equal(6, forecasts[4].Number); Assert.Equal(1, forecasts[4].OwnersGoals); Assert.Equal(0, forecasts[4].GuestsGoals); Assert.Equal(7, forecasts[5].Number); Assert.Equal(0, forecasts[5].OwnersGoals); Assert.Equal(0, forecasts[5].GuestsGoals); Assert.Equal(8, forecasts[6].Number); Assert.Equal(0, forecasts[6].OwnersGoals); Assert.Equal(0, forecasts[6].GuestsGoals); }
public void CreateSlackMessage_WhenIsCloudyAndRainy_ShouldReturnProperText() { const string textualForecast = "Det blir delvis skyet på morgenen og i kveld, regn i ettermiddag."; var forecast = ParseIntervals( @"Start: 11/26/2017 7:00:00 AM End: 11/26/2017 8:00:00 AM Temperature: 2.5 Wind: 5 Rain: 0.5 Start: 11/26/2017 8:00:00 AM End: 11/26/2017 9:00:00 AM Temperature: 2.2 Wind: 2.8 Rain: 0 Start: 11/26/2017 9:00:00 AM End: 11/26/2017 10:00:00 AM Temperature: 2.2 Wind: 2.1 Rain: 0 Start: 11/26/2017 10:00:00 AM End: 11/26/2017 11:00:00 AM Temperature: 2.7 Wind: 2 Rain: 0 Start: 11/26/2017 11:00:00 AM End: 11/26/2017 12:00:00 PM Temperature: 2.7 Wind: 2.5 Rain: 0 Start: 11/26/2017 12:00:00 PM End: 11/26/2017 1:00:00 PM Temperature: 2.5 Wind: 2.2 Rain: 0.5 Start: 11/26/2017 1:00:00 PM End: 11/26/2017 2:00:00 PM Temperature: 2.5 Wind: 1.5 Rain: 0.9 Start: 11/26/2017 2:00:00 PM End: 11/26/2017 3:00:00 PM Temperature: 2 Wind: 2.7 Rain: 0.6 Start: 11/26/2017 3:00:00 PM End: 11/26/2017 4:00:00 PM Temperature: 1.8 Wind: 3.2 Rain: 0.3 Start: 11/26/2017 4:00:00 PM End: 11/26/2017 5:00:00 PM Temperature: 1.8 Wind: 3.2 Rain: 0 Start: 11/26/2017 5:00:00 PM End: 11/26/2017 6:00:00 PM Temperature: 1.8 Wind: 2.9 Rain: 0 Start: 11/26/2017 6:00:00 PM End: 11/26/2017 7:00:00 PM Temperature: 1.7 Wind: 2.6 Rain: 0 Start: 11/26/2017 7:00:00 PM End: 11/26/2017 8:00:00 PM Temperature: 1.5 Wind: 2.8 Rain: 0 Start: 11/26/2017 8:00:00 PM End: 11/26/2017 9:00:00 PM Temperature: 1.1 Wind: 2.1 Rain: 0 Start: 11/26/2017 9:00:00 PM End: 11/26/2017 10:00:00 PM Temperature: 0.7 Wind: 1.4 Rain: 0 Start: 11/26/2017 10:00:00 PM End: 11/26/2017 11:00:00 PM Temperature: 1.2 Wind: 0.5 Rain: 0"); var result = new ForecastParser().CreateSlackMessage(textualForecast, forecast); Assert.Equal(@"Det blir delvis skyet på morgenen og i kveld, regn i ettermiddag. :thermometer: Temperaturen svinger mellom 2,7° kl. 10 og 0,7° kl. 21. :rain_cloud: Mest nedbør mellom kl 13 og 14, med 0,9 mm. Totalt 2,8 mm. :wind_blowing_face: Mest vind mellom kl 07 og 08, med 5 m/s.", result); }
public void CreateSlackMessage_WhenLowestTemperatureIsLaterThanHighest_ShouldReturnChronological() { const string textualForecast = "Det blir lettskyet i dag og delvis skyet i kveld."; var forecast = ParseIntervals( @"Start: 11/18/2017 7:00:00 AM End: 11/18/2017 8:00:00 AM Temperature: 1.4 Wind: 1.9 Rain: 0 Start: 11/18/2017 8:00:00 AM End: 11/18/2017 9:00:00 AM Temperature: 0.6 Wind: 1.7 Rain: 0 Start: 11/18/2017 9:00:00 AM End: 11/18/2017 10:00:00 AM Temperature: 0.4 Wind: 1.4 Rain: 0 Start: 11/18/2017 10:00:00 AM End: 11/18/2017 11:00:00 AM Temperature: 1.4 Wind: 0.6 Rain: 0 Start: 11/18/2017 11:00:00 AM End: 11/18/2017 12:00:00 PM Temperature: 2.2 Wind: 1.1 Rain: 0 Start: 11/18/2017 12:00:00 PM End: 11/18/2017 1:00:00 PM Temperature: 2.9 Wind: 1 Rain: 0 Start: 11/18/2017 1:00:00 PM End: 11/18/2017 2:00:00 PM Temperature: 3.5 Wind: 1.6 Rain: 0 Start: 11/18/2017 2:00:00 PM End: 11/18/2017 3:00:00 PM Temperature: 3.6 Wind: 2.1 Rain: 0 Start: 11/18/2017 3:00:00 PM End: 11/18/2017 4:00:00 PM Temperature: 3.3 Wind: 2.7 Rain: 0 Start: 11/18/2017 4:00:00 PM End: 11/18/2017 5:00:00 PM Temperature: 2 Wind: 2.7 Rain: 0 Start: 11/18/2017 5:00:00 PM End: 11/18/2017 6:00:00 PM Temperature: 1.5 Wind: 2.4 Rain: 0 Start: 11/18/2017 6:00:00 PM End: 11/18/2017 7:00:00 PM Temperature: 0.9 Wind: 2.4 Rain: 0 Start: 11/18/2017 7:00:00 PM End: 11/18/2017 8:00:00 PM Temperature: 0.3 Wind: 1.7 Rain: 0 Start: 11/18/2017 8:00:00 PM End: 11/18/2017 9:00:00 PM Temperature: 0 Wind: 1.8 Rain: 0 Start: 11/18/2017 9:00:00 PM End: 11/18/2017 10:00:00 PM Temperature: 0 Wind: 2.9 Rain: 0 Start: 11/18/2017 10:00:00 PM End: 11/18/2017 11:00:00 PM Temperature: 0.2 Wind: 4 Rain: 0"); var result = new ForecastParser().CreateSlackMessage(textualForecast, forecast); Assert.Equal(@"Det blir lettskyet i dag og delvis skyet i kveld. :thermometer: Temperaturen svinger mellom 3,6° kl. 14 og 0° kl. 20. :cloud: Det er ikke meldt noe nedbør! :smiley: :wind_blowing_face: Mest vind mellom kl 22 og 23, med 4 m/s.", result); }
public ActionResult ParseTourResult(ParseMatchesResultModel model) { string html = HtmlDownloader.GetHtml(model.Url); string s = new ForecastParser(QueryFactory, log, UnitOfWorkFactory).ParseResult(html); return(View(new ParseMatchesResultModel { Result = s })); }
public void TestOne() { List <Forecast> forecasts = ForecastParser.Parse("<div class=\"talk-comment-box\">15. 1:1<p style=\"margin: 0.7em 0 0.2em 0\"><font size=\"-2\">(<a href=\"http://ru-football.livejournal.com/7200790.html?replyto=440510742\" onclick=\"return QuickReply.reply('440510742',1720745,'')\" rel=\"nofollow\">Ответить</a>) </font></p><div id=\"ljqrt440510742\" name=\"ljqrt440510742\"></div></div>", new Ljuser()).ToList(); Assert.Equal(1, forecasts.Count); Assert.Equal(15, forecasts[0].Number); Assert.Equal(1, forecasts[0].OwnersGoals); Assert.Equal(1, forecasts[0].GuestsGoals); }
public void OnAPILoadCompleted(String result) { ListItemSource.Clear(); if (result == null || "".Equals(result)) { HandleNullData(true); } else { List <RichListItem> listResult = new List <RichListItem>(); switch (Template) { case WeatherItemTemplate.WI_TEMPLATE_AREA: listResult = ForecastParser.Parse(result); AddForecastItems(listResult); break; case WeatherItemTemplate.WI_TEMPLATE_OBS: listResult = OBSParser.Parse(result); AddOBSItems(listResult); break; case WeatherItemTemplate.WI_TEMPLATE_WEEK: listResult = WeekParser.Parse(result); AddWeekItems(listResult); break; case WeatherItemTemplate.WI_TEMPLATE_SEA: listResult = SeaParser.Parse(result); AddSeaItems(listResult); break; case WeatherItemTemplate.WI_TEMPLATE_NEARSEA: listResult = NearSeaParser.Parse(result); AddNearSeaItems(listResult); break; case WeatherItemTemplate.WI_TEMPLATE_TIDE: listResult = TideParser.Parse(result); AddTideItems(listResult); break; case WeatherItemTemplate.WI_TEMPLATE_GLOBAL: listResult = GlobalParser.Parse(result); AddGlobalItems(listResult); break; } listResult = null; } if (LoadDataCompleted != null) { LoadDataCompleted(); } }
public void CreateSlackMessage_WhenPrecipitationAndFreezing_ShouldUseSnowCloudEmoji() { var text = new ForecastParser().CreateSlackMessage( string.Empty, CreateForecast(precipitation: 3, temperature: -3)); Assert.Equal(@":thermometer: Temperaturen svinger mellom -3° kl. 14 og -3° kl. 14. :snow_cloud: Mest nedbør mellom kl 14 og 14, med 3 mm. Totalt 3 mm. :wind_blowing_face: Mest vind mellom kl 14 og 14, med 4 m/s.", text); }
public void CreateSlackMessage_WhenNoPrecipitation_ShouldUseDryCloudEmoji() { var text = new ForecastParser().CreateSlackMessage( string.Empty, CreateForecast(precipitation: 0)); Assert.Equal(@":thermometer: Temperaturen svinger mellom 10° kl. 14 og 10° kl. 14. :cloud: Det er ikke meldt noe nedbør! :smiley: :wind_blowing_face: Mest vind mellom kl 14 og 14, med 4 m/s.", text); }
public void OnForecastAPILoadCompleted(String result) { Boolean bIsRemember = AppService.Instance.GetIsRemember(); Boolean bResultOK = true; Boolean bLocalData = false; if ((result == null || "".Equals(result)) && bIsRemember) { String strLocalData = AppService.Instance.GetBackUpAllForecast(); if (strLocalData == null || "".Equals(strLocalData)) { bResultOK = false; if (LoadDataError != null) { LoadDataError(); } } else { bLocalData = true; result = strLocalData; } } else if (result == null || "".Equals(result)) { bResultOK = false; if (LoadDataError != null) { LoadDataError(); } } if (bResultOK) { Dictionary <String, List <RichListItem> > allForecast = ForecastParser.ParseAllForecast(result); AppService.Instance.mAreaWeatherList = allForecast; TileService.Instance.mAreaWeatherList = allForecast; if (allForecast != null && allForecast.Count > 0 && !bLocalData) { AppService.Instance.SaveBackUpAllForecast(result); } UpdateMyWeatherPage(); } if (LoadDataCompleted != null) { LoadDataCompleted(); } }
public void TestEndSpaces() { List <Forecast> forecasts = ForecastParser.Parse(@"33. 1:1 <br />34. 0:2 <br />35. 1:0 <br />36. 0:1 <br />37. 1:0 <br />38. 0:3 <br />39. 0:0 <br />40. 2:0 <br /><p style='margin: 0.7em 0 0.2em 0'><font size='-2'>(<a href='http://ru-football.livejournal.com/7228809.html?replyto=431103625' rel='nofollow'>Reply to this</a>) </font></p>", new Ljuser()).ToList(); Assert.Equal(8, forecasts.Count); Assert.Equal(33, forecasts[0].Number); Assert.Equal(1, forecasts[0].OwnersGoals); Assert.Equal(1, forecasts[0].GuestsGoals); Assert.Equal(34, forecasts[1].Number); Assert.Equal(0, forecasts[1].OwnersGoals); Assert.Equal(2, forecasts[1].GuestsGoals); }
public void TestSix() { List <Forecast> forecasts = ForecastParser.Parse("1. 0:1<br>2. 160<br>", new Ljuser()).ToList(); Assert.Equal(2, forecasts.Count); Assert.Equal(1, forecasts[0].Number); Assert.Equal(0, forecasts[0].OwnersGoals); Assert.Equal(1, forecasts[0].GuestsGoals); Assert.Equal(2, forecasts[1].Number); Assert.Equal(1, forecasts[1].OwnersGoals); Assert.Equal(0, forecasts[1].GuestsGoals); }
public ActionResult ParseTourFromUrl(ParseUrlModel model) { selenium = new DefaultSelenium("localhost", 4444, "*firefox", "http://localhost"); selenium.Start(); selenium.SetTimeout("120000"); selenium.Open(model.Url); selenium.WaitForPageToLoad("60000"); var html = selenium.GetHtmlSource(); selenium.Stop(); // string html = HtmlDownloader.GetHtml(model.Url); string s = new ForecastParser(QueryFactory, log, UnitOfWorkFactory).ParseHtml(html, model.Url); return(View(new ParseUrlModel { Result = s })); }
public void CreateSlackMessage_WhenTemperatureTurnsNegative_ShouldReturnProperText() { const string textualForecast = "Det blir delvis skyet resten av dagen."; var forecast = ParseIntervals( @"Start: 11/25/2017 3:00:00 PM End: 11/25/2017 4:00:00 PM Temperature: 2.2 Wind: 2 Rain: 0 Start: 11/25/2017 4:00:00 PM End: 11/25/2017 5:00:00 PM Temperature: 1.3 Wind: 2 Rain: 0 Start: 11/25/2017 5:00:00 PM End: 11/25/2017 6:00:00 PM Temperature: 1.1 Wind: 3.2 Rain: 0 Start: 11/25/2017 6:00:00 PM End: 11/25/2017 7:00:00 PM Temperature: 0.9 Wind: 3.2 Rain: 0 Start: 11/25/2017 7:00:00 PM End: 11/25/2017 8:00:00 PM Temperature: 0.4 Wind: 2.8 Rain: 0 Start: 11/25/2017 8:00:00 PM End: 11/25/2017 9:00:00 PM Temperature: 0.1 Wind: 2.5 Rain: 0 Start: 11/25/2017 9:00:00 PM End: 11/25/2017 10:00:00 PM Temperature: 0 Wind: 2.8 Rain: 0 Start: 11/25/2017 10:00:00 PM End: 11/25/2017 11:00:00 PM Temperature: -0.2 Wind: 3.2 Rain: 0"); var result = new ForecastParser().CreateSlackMessage(textualForecast, forecast); Assert.Equal(@"Det blir delvis skyet resten av dagen. :thermometer: Temperaturen svinger mellom 2,2° kl. 15 og -0,2° kl. 22. :cloud: Det er ikke meldt noe nedbør! :smiley: :wind_blowing_face: Mest vind mellom kl 17 og 18, med 3,2 m/s.", result); }
public void TestFool() { List <Forecast> forecasts = ForecastParser.Parse(@"19 марта, суббота<br>9. Динамо : Ростов 1:1<br>10. Краснодар : Спартак-Нч 0:0<br><br>20 марта, воскресенье<br>11. Амкар : Локомотив 1:0<br>12. Томь : Кубань 0:0<br>13. Рубин : Терек 2:1<br><br>21 марта, понедельник<br>14. Зенит : Анжи 2:0<br>15. Кр. Советов : ЦСКА 1:3<br>16. Спартак : Волга 2:1<p style=""margin: 0.7em 0 0.2em 0""><font size=""-2"">(<a href=""http://www.livejournal.com/talkscreen.bml?mode=unscreen&journal=ru_football&talkid=425504278"">Раскрыть для ответов</a>) </font></p>", new Ljuser()).ToList(); Assert.Equal(8, forecasts.Count); Assert.Equal(9, forecasts[0].Number); Assert.Equal(1, forecasts[0].OwnersGoals); Assert.Equal(1, forecasts[0].GuestsGoals); Assert.Equal(10, forecasts[1].Number); Assert.Equal(0, forecasts[1].OwnersGoals); Assert.Equal(0, forecasts[1].GuestsGoals); Assert.Equal(11, forecasts[2].Number); Assert.Equal(1, forecasts[2].OwnersGoals); Assert.Equal(0, forecasts[2].GuestsGoals); Assert.Equal(12, forecasts[3].Number); Assert.Equal(0, forecasts[3].OwnersGoals); Assert.Equal(0, forecasts[3].GuestsGoals); Assert.Equal(13, forecasts[4].Number); Assert.Equal(2, forecasts[4].OwnersGoals); Assert.Equal(1, forecasts[4].GuestsGoals); Assert.Equal(14, forecasts[5].Number); Assert.Equal(2, forecasts[5].OwnersGoals); Assert.Equal(0, forecasts[5].GuestsGoals); Assert.Equal(15, forecasts[6].Number); Assert.Equal(1, forecasts[6].OwnersGoals); Assert.Equal(3, forecasts[6].GuestsGoals); Assert.Equal(16, forecasts[7].Number); Assert.Equal(2, forecasts[7].OwnersGoals); Assert.Equal(1, forecasts[7].GuestsGoals); }
public void TestTire() { List <Forecast> forecasts = ForecastParser.Parse("1. 0-1<br>2. 1-0<br>3. 1 - 1<br>4. 0 -1<br>5. 1- 1<br>6. 2–1<br>7. 0 – 1<br>8. 20– 2", new Ljuser()).ToList(); Assert.Equal(8, forecasts.Count); Assert.Equal(1, forecasts[0].Number); Assert.Equal(0, forecasts[0].OwnersGoals); Assert.Equal(1, forecasts[0].GuestsGoals); Assert.Equal(2, forecasts[1].Number); Assert.Equal(1, forecasts[1].OwnersGoals); Assert.Equal(0, forecasts[1].GuestsGoals); Assert.Equal(3, forecasts[2].Number); Assert.Equal(1, forecasts[2].OwnersGoals); Assert.Equal(1, forecasts[2].GuestsGoals); Assert.Equal(4, forecasts[3].Number); Assert.Equal(0, forecasts[3].OwnersGoals); Assert.Equal(1, forecasts[3].GuestsGoals); Assert.Equal(5, forecasts[4].Number); Assert.Equal(1, forecasts[4].OwnersGoals); Assert.Equal(1, forecasts[4].GuestsGoals); Assert.Equal(6, forecasts[5].Number); Assert.Equal(2, forecasts[5].OwnersGoals); Assert.Equal(1, forecasts[5].GuestsGoals); Assert.Equal(7, forecasts[6].Number); Assert.Equal(0, forecasts[6].OwnersGoals); Assert.Equal(1, forecasts[6].GuestsGoals); Assert.Equal(8, forecasts[7].Number); Assert.Equal(20, forecasts[7].OwnersGoals); Assert.Equal(2, forecasts[7].GuestsGoals); }
public void TestCounter() { List <Forecast> forecasts = ForecastParser.Parse(@"Спасибо! <img src=""http://s03.flagcounter.com/count/YVK/bg=ffffff/txt=ffffff/border=ffffff/columns=1/maxflags=1/viewers=0/labels=0/.jpg"" width=""1"" height=""1""><img src=""http://2.s03.flagcounter.com/count/YVK/bg=ffffff/txt=ffffff/border=ffffff/columns=1/maxflags=1/viewers=0/labels=0/.jpg"" width=""1"" height=""1""><br><p style=""margin: 0.7em 0 0.2em 0""><font size=""-2"">(<a href=""http://community.livejournal.com/ru_football/7220672.html?replyto=429694400"" onclick=""return QuickReply.reply('429694400',1678493,'')"">Ответить</a>) </font></p>", new Ljuser()).ToList(); Assert.Equal(0, forecasts.Count); }
public void TestEmpty() { List <Forecast> forecasts = ForecastParser.Parse("так этот прогноз<p style='margin: 0.7em 0 0.2em 0'><font size='-2'>(<a href='http://community.livejournal.com/ru_football/7192133.html?replyto=425417029'>Reply to this</a>) (<a href='http://community.livejournal.com/ru_football/7192133.html?thread=424197701#t424197701'>Parent</a>) </font></p>", new Ljuser()).ToList(); Assert.Equal(0, forecasts.Count); }