コード例 #1
0
        public BetsResponse Parse(string html, AgilityRestManager arm, TipsterResponse tipster, ExtendedTime fromDateClientLocal, TimeZoneKind serverTimezone)
        {
            HandleErrors(html);

            var fromDate = fromDateClientLocal?.ToTimezone(serverTimezone); // konwertuj na strefę czasową serwera, nie znamy czasu serwera, prawdopodobnie UTC
            var newBets  = new List <BetResponse>();

            var spanBettingPicks = html.HtmlRoot()
                                   .Descendants()
                                   .Where(n => n.HasClass("bettingpick"))
                                   .ToArray();

            var i = 0;

            var brpLs = LocalizationManager.GetLoaderBetshootResponseParseLocalizedStrings();

            foreach (var spanBp in spanBettingPicks)
            {
                OnInformationSending($"{brpLs[0][0]} ({++i} {brpLs[0][1]} {spanBettingPicks.Length})..."); // ($"Wczytywanie zakładów ({++i} z {spanBettingPicks.Length})...");
                var strDate = spanBp.Descendants()
                              .Single(x => x.HasClass("bettingpickdate"))
                              .InnerText;
                var dateArr            = strDate.Split('-').Swap(0, 2);
                var date               = new ExtendedTime(new DateTime(dateArr[2].ToInt(), dateArr[1].ToInt(), dateArr[0].ToInt()));
                var spanBetResultClass = spanBp.Descendants("span")
                                         .Single(span => span.HasClass("mgreen", "mred", "morange", "munits2"))
                                         .GetOnlyClass(); // fix opisany w konwerterze
                var stake  = spanBp.Descendants("span").Single(span => span.HasClass("pick-stake")).InnerText.Trim().ToInt();
                var profit = spanBp.Descendants("span").Single(span => span.HasClass("munits")).InnerText.Trim().ToDoubleN();

                var pickStr           = spanBp.Descendants("span").Single(span => span.HasClass("predict")).InnerText.RemoveHTMLSymbols();
                var spanPickTeams     = spanBp.Descendants("span").Single(span => span.HasClass("pick-teams"));
                var aPickTeams        = spanPickTeams.Descendants("a").SingleOrDefault();
                var matchStr          = (aPickTeams ?? spanPickTeams).InnerText.RemoveHTMLSymbols();
                var rawMatchResultStr = spanBp.Descendants("span").Single(x => x.HasClass("mresult")).InnerText;
                var odds = spanBp.Descendants("span").Single(x => x.HasClass("pick-odd")).InnerText.ToDouble();

                var    hrefAPickTeams = aPickTeams?.GetAttributeValue("href", "");
                string disciplineStr  = null;
                string leagueName     = null;
                if (hrefAPickTeams != null)
                {
                    var disciplineLeagueStr = arm.GetHtml(hrefAPickTeams).HtmlRoot().Descendants("p")
                                              .Single(p => p.InnerText.Trim().EndsWithAny(tipster.Name)).InnerText.RemoveHTMLSymbols().Split(" - ");
                    disciplineStr = disciplineLeagueStr[0];
                    leagueName    = disciplineLeagueStr[1];
                }

                var newBet = new BetResponse
                {
                    Date        = date,
                    HomeName    = matchStr.BeforeFirst(" - "),
                    AwayName    = matchStr.AfterFirst(" - "),
                    Pick        = PickConverter.ParseToPickResponse(pickStr, matchStr),
                    MatchResult = MatchConverter.ToMatchResultResponse(rawMatchResultStr),
                    BetResult   = BetConverter.ParseBetshootResultStringToBetResult(spanBetResultClass, stake, odds, profit),
                    Odds        = odds,
                    Discipline  = DisciplineConverter.ToDisciplineTypeOrNull(disciplineStr),
                    LeagueName  = leagueName
                };

                if (fromDate != null && date < fromDate)
                {
                    break;
                }

                newBets.Add(newBet);
            }

            OnInformationSending(brpLs[1][0]);

            Tipster = tipster;
            Bets    = newBets;
            return(this);
        }
コード例 #2
0
ファイル: BetsResponse.cs プロジェクト: rvnlord/BettingBot
        public BetsResponse Parse(HintwiseSeleniumDriverManager sdm, TipsterResponse tipster, ExtendedTime fromDateClientLocal, TimeZoneKind serverTimezone)
        {
            HandleErrors(sdm);

            OnInformationSending("Zbieranie dodatkowych informacji...");

            const string matchSep        = " vs ";
            var          originalAddress = sdm.Url;
            var          fromDate        = fromDateClientLocal?.ToTimezone(serverTimezone); // konwertuj na strefę czasową serwera
            var          newBets         = new List <BetResponse>();

            IWebElement getDivCurrentPredictions() => sdm.FindElementByXPath(".//div[@id='predictions-grid']");

            var divCurrentPredictions   = getDivCurrentPredictions();
            var currPredLastPageQueries = sdm.PagerLastPageQueries(divCurrentPredictions);
            var currPredPagesCount      = sdm.PagerLastPage(currPredLastPageQueries);

            IWebElement getDivHistoricalPredictions() => sdm.FindElementByXPath(".//div[@id='history-predictions']");

            var divHistoricalPredictions = getDivHistoricalPredictions();
            var histPredLastPageQueries  = sdm.PagerLastPageQueries(divHistoricalPredictions);
            var histPredPagesCount       = sdm.PagerLastPage(histPredLastPageQueries);

            var previousDate = ExtendedTime.UtcNow.ToTimezone(serverTimezone); // w strefie czassowej serwera
            var year         = previousDate.Rfc1123.Year;

            OnInformationSending("Wczytywanie informacji o zakładach...");

            // Obecne Zakłady

            for (var currPage = 1; currPage <= currPredPagesCount; currPage++)
            {
                OnInformationSending($"Wczytywanie nowych zakładów (strona {currPage} z {currPredPagesCount})...");

                if (divCurrentPredictions.FindElement(By.TagName("span")).Text.ToLower().Contains("no results found"))
                {
                    break;
                }

                sdm.PagerNavigateToCurrentPage(currPage, currPredLastPageQueries, originalAddress);
                divCurrentPredictions = getDivCurrentPredictions();
                var trCurrPredRows = divCurrentPredictions.FindElements(By.XPath(".//table[@class='items']/tbody/tr"));

                foreach (var trCurrPredRow in trCurrPredRows)
                {
                    var tdCurrPredRowCells = trCurrPredRow.FindElements(By.TagName("td"));

                    sdm.DisableWaitingForElements();
                    var isFree = tdCurrPredRowCells[3].FindElements(By.XPath("input[@type='button']")).Count == 0;
                    sdm.EnableWaitingForElements();

                    var extDate    = ParseDate(tdCurrPredRowCells[0].Text, previousDate, serverTimezone, ref year);
                    var discipline = DisciplineConverter.ToDisciplineType(tdCurrPredRowCells[1].Text.Trim());
                    var matchStr   = tdCurrPredRowCells[2].FindElement(By.TagName("a")).Text.RemoveHTMLSymbols().Trim();
                    var pickStr    = isFree ? tdCurrPredRowCells[3].Text.BeforeFirst("(").RemoveHTMLSymbols().Trim() : "Ukryty";

                    var newBet = new BetResponse
                    {
                        Date        = extDate, // czas pobierany ma być zawsze w UTC
                        HomeName    = matchStr.BeforeFirst(matchSep),
                        AwayName    = matchStr.AfterFirst(matchSep),
                        Pick        = PickConverter.ParseToPickResponse(pickStr, matchStr),
                        MatchResult = MatchResult.Inconclusive(),
                        BetResult   = BetResult.Pending,
                        Odds        = 0,
                        Discipline  = discipline
                    };
                    newBets.Add(newBet);
                }
            }

            // Historyczne wyniki

            for (var currPage = 1; currPage <= histPredPagesCount; currPage++) //
            {
                OnInformationSending($"Wczytywanie historycznych zakładów (strona {currPage} z {histPredPagesCount})...");

                if (divHistoricalPredictions.FindElement(By.TagName("span")).Text.ToLower().Contains("no results found"))
                {
                    break;
                }

                sdm.PagerNavigateToCurrentPage(currPage, histPredLastPageQueries, originalAddress);
                divHistoricalPredictions = getDivHistoricalPredictions();
                var trHistPredRows = divHistoricalPredictions.FindElements(By.XPath(".//table[@class='items']/tbody/tr"));

                foreach (var trHistPredRow in trHistPredRows)
                {
                    var tdHistPredRowCells = trHistPredRow.FindElements(By.TagName("td"));

                    var extDate           = ParseDate(tdHistPredRowCells[0].Text, previousDate, serverTimezone, ref year);
                    var discipline        = DisciplineConverter.ToDisciplineType(tdHistPredRowCells[1].Text.Trim());
                    var matchStr          = tdHistPredRowCells[2].FindElement(By.TagName("a")).Text.RemoveHTMLSymbols().Trim();
                    var pickStr           = tdHistPredRowCells[3].Text.BeforeFirst("(").RemoveHTMLSymbols().Trim();
                    var rawMatchResultStr = tdHistPredRowCells[4].Text.RemoveHTMLSymbols().Trim();
                    var betResult         = tdHistPredRowCells[5].Text.BeforeFirst("(").RemoveHTMLSymbols().Trim().ToLower() == "win"
                        ? BetResult.Won : BetResult.Lost;
                    var odds = tdHistPredRowCells[3].Text.Between("(", ")").RemoveHTMLSymbols().Trim().ToDouble();

                    var newBet = new BetResponse
                    {
                        Date        = extDate,
                        HomeName    = matchStr.BeforeFirst(matchSep),
                        AwayName    = matchStr.AfterFirst(matchSep),
                        Pick        = PickConverter.ParseToPickResponse(pickStr, matchStr),
                        MatchResult = MatchConverter.ToMatchResultResponse(rawMatchResultStr),
                        BetResult   = betResult,
                        Odds        = odds,
                        Discipline  = discipline
                    };

                    previousDate = extDate;
                    newBets.Add(newBet);

                    if (fromDate != null && extDate < fromDate)
                    {
                        break;
                    }
                }

                if (fromDate != null && newBets.Last().Date < fromDate)
                {
                    newBets.Remove(newBets.Last());
                    break;
                }
            }

            OnInformationSending("Wczytano zakłady");

            Tipster = tipster;
            Bets    = newBets;
            return(this);
        }