Пример #1
0
        private void ReadInformation(DriverWrapper driver, List <aMatch> foundMatches, string leagueText, string marker)
        {
            var sections = driver.FindElements(By.ClassName("Section"));

            if (sections.Count() == 0)
            {
                log.Warn("No sections found :(");
                return;
            }

            var sectionTexts = Regex.Split(sections.First().Text, "\r\n").ToList();

            sectionTexts.RemoveAt(0);

            var sectionCount = sectionTexts.Where(x => x.Contains(marker)).Count();

            log.Debug(sectionTexts.Count());

            for (int j = 0; j < sectionCount; ++j)
            {
                var txt = Chomp(sectionTexts);

                if (txt.Contains(marker))
                {
                    DateTime koDate;

                    bool parsed = DateTime.TryParse(txt.Substring(0, txt.IndexOf(marker)), out koDate);

                    while (true)
                    {
                        if (sectionTexts.Count() == 0)
                        {
                            break;
                        }

                        if (sectionTexts.First().Contains(marker) == true)
                        {
                            break;
                        }

                        var team1 = DoSubstitutions(Chomp(sectionTexts));
                        var team2 = DoSubstitutions(Chomp(sectionTexts));

                        //search for teams already in matches list here.
                        var m = foundMatches.SingleOrDefault(x => x.team1 == team1 && x.team2 == team2);

                        bool needToAdd = false;

                        if (m == null)
                        {
                            m         = new aMatch();
                            needToAdd = true;
                        }

                        m.koDateTime = koDate;
                        m.league     = DoSubstitutions(leagueText);

                        m.team1 = team1;
                        m.team2 = team2;

                        var kodate = Chomp(sectionTexts);
                        var hours  = kodate.Substring(0, 2);
                        var mins   = kodate.Substring(3, 2);

                        try
                        {
                            m.koDateTime = m.koDateTime.AddHours(Double.Parse(hours));
                            m.koDateTime = m.koDateTime.AddMinutes(Double.Parse(mins));
                        }
                        catch (Exception)
                        {
                            Console.WriteLine("Exception trying to parse hours: [" + hours + "] + minutes [" + mins + "]");
                        }

                        //goals
                        if (marker == " 1 X 2")
                        {
                            var pricesText = Chomp(sectionTexts);
                            if (char.IsDigit(pricesText[0]))
                            {
                                var prices = pricesText.Split(' ');

                                m.homeWinPrice = GetUkOddsPrice(prices[0]).ToString();
                                m.drawPrice    = GetUkOddsPrice(prices[1]).ToString();
                                m.awayWinPrice = GetUkOddsPrice(prices[2]).ToString();

                                if (needToAdd)
                                {
                                    foundMatches.Add(m);
                                }

                                Console.WriteLine("Found: " + m.team1 + " v " + m.team2 + " in " + m.league + " at " + m.koDateTime + " Prices: " + pricesText);
                            }
                            else
                            {
                                Console.WriteLine("Unrecognised price format: " + pricesText);
                            }
                        }
                        //corners
                        else
                        {
                            var pricesText1 = Chomp(sectionTexts);
                            if (char.IsDigit(pricesText1[0]))
                            {
                                var prices = pricesText1.Split(' ');

                                m.homeAsianCornerPrice = prices[0];
                                m.cornerLine           = prices[1];

                                var pricesText2 = Chomp(sectionTexts);
                                m.awayAsianCornerPrice = pricesText2;

                                if (needToAdd)
                                {
                                    foundMatches.Add(m);
                                }

                                Console.WriteLine("Found: " + m.team1 + " v " + m.team2 + " in " + m.league + " at " + m.koDateTime + " Corner Prices: " + pricesText1 + " " + pricesText2);
                            }
                            else
                            {
                                Console.WriteLine("Unrecognised price format: " + pricesText1);
                            }
                        }
                    }
                }
            }
        }
Пример #2
0
        private void GetRaceToCornerData(DriverWrapper driver, List <aMatch> foundMatches, int raceToValue)
        {
            var rowsCount = driver.FindElements(By.ClassName("genericRow")).Count();

            for (int i = 0; i < rowsCount; ++i)
            {
                try
                {
                    var genItems = driver.FindElements(By.ClassName("genericRow"));

                    IWebElement genItem = null;
                    if (i < genItems.Count())
                    {
                        genItem = genItems.ElementAt(i);
                    }
                    else
                    {
                        Console.WriteLine("Can't find item at index: " + i);
                        break;
                    }

                    string leagueText = genItem.Text.Trim();
                    genItem.Click();
                    driver.ForceSleep(m_sleepTime);

                    var sectionCount = driver.FindElements(By.ClassName("Section")).Count();

                    for (int j = 1; j < sectionCount; ++j)
                    {
                        var sections = driver.FindElements(By.ClassName("Section"));
                        if (j < sections.Count())
                        {
                            try
                            {
                                sections.ElementAt(j).Click();
                            }
                            catch (Exception)
                            {
                                Console.WriteLine("Exception caught trying to click at index: " + j);
                            }

                            driver.ForceSleep(500);
                        }
                        else
                        {
                            Console.WriteLine("Can't find item at index: " + j);
                            break;
                        }
                    }


                    sectionCount = driver.FindElements(By.ClassName("Section")).Count();

                    for (int j = 0; j < sectionCount; ++j)
                    {
                        var sections = driver.FindElements(By.ClassName("Section"));

                        if (j > sections.Count())
                        {
                            Console.WriteLine("Can't find item at index: " + j);
                            break;
                        }

                        var section = sections.ElementAt(j);

                        string sectionText = section.Text;

                        var bits = Regex.Split(sectionText, "\r\n").ToList();
                        bits.ForEach(x => x.Trim());

                        string matchText = bits.ElementAt(0);

                        if (matchText.Contains("\r\n"))
                        {
                            matchText = matchText.Substring(0, matchText.IndexOf("\r\n"));
                        }

                        if (matchText.Contains(" v "))
                        {
                            var teamSplits = Regex.Split(matchText, " v ");

                            var m = new aMatch();
                            m.team1 = teamSplits.ElementAt(0);
                            m.team2 = teamSplits.ElementAt(1);

                            m.team1  = DoSubstitutions(m.team1);
                            m.team2  = DoSubstitutions(m.team2);
                            m.league = DoSubstitutions(leagueText);

                            var thisMatch = foundMatches.SingleOrDefault(x => x.team1 == m.team1 && x.team2 == m.team2);

                            if (thisMatch != null && bits.Count() == 5)
                            {
                                if (bits.ElementAt(2).Contains("  "))
                                {
                                    if (raceToValue == 3)
                                    {
                                        thisMatch.homeRaceTo3CornersPrice = GetUkOddsPrice(bits.ElementAt(2)).ToString();
                                    }
                                    if (raceToValue == 5)
                                    {
                                        thisMatch.homeRaceTo5CornersPrice = GetUkOddsPrice(bits.ElementAt(2)).ToString();
                                    }
                                    if (raceToValue == 7)
                                    {
                                        thisMatch.homeRaceTo7CornersPrice = GetUkOddsPrice(bits.ElementAt(2)).ToString();
                                    }
                                    if (raceToValue == 9)
                                    {
                                        thisMatch.homeRaceTo9CornersPrice = GetUkOddsPrice(bits.ElementAt(2)).ToString();
                                    }
                                }

                                if (bits.ElementAt(3).Contains("  "))
                                {
                                    if (raceToValue == 3)
                                    {
                                        thisMatch.awayRaceTo3CornersPrice = GetUkOddsPrice(bits.ElementAt(3)).ToString();
                                    }
                                    if (raceToValue == 5)
                                    {
                                        thisMatch.awayRaceTo5CornersPrice = GetUkOddsPrice(bits.ElementAt(3)).ToString();
                                    }
                                    if (raceToValue == 7)
                                    {
                                        thisMatch.awayRaceTo7CornersPrice = GetUkOddsPrice(bits.ElementAt(3)).ToString();
                                    }
                                    if (raceToValue == 9)
                                    {
                                        thisMatch.awayRaceTo9CornersPrice = GetUkOddsPrice(bits.ElementAt(3)).ToString();
                                    }
                                }

                                if (bits.ElementAt(4).Contains("  "))
                                {
                                    if (raceToValue == 3)
                                    {
                                        thisMatch.neitherRaceTo3CornersPrice = GetUkOddsPrice(bits.ElementAt(4)).ToString();
                                    }
                                    if (raceToValue == 5)
                                    {
                                        thisMatch.neitherRaceTo5CornersPrice = GetUkOddsPrice(bits.ElementAt(4)).ToString();
                                    }
                                    if (raceToValue == 7)
                                    {
                                        thisMatch.neitherRaceTo7CornersPrice = GetUkOddsPrice(bits.ElementAt(4)).ToString();
                                    }
                                    if (raceToValue == 9)
                                    {
                                        thisMatch.neitherRaceTo9CornersPrice = GetUkOddsPrice(bits.ElementAt(4)).ToString();
                                    }
                                }
                            }
                            else
                            {
                                Console.WriteLine("Error occurred");
                            }
                        }
                        else
                        {
                            Console.WriteLine("Can't get match from " + matchText);
                        }
                    }
                }
                catch (Exception ce)
                {
                    Console.WriteLine("Exception caught: " + ce);
                }

                IJavaScriptExecutor js = driver.Driver as IJavaScriptExecutor;
                js.ExecuteScript("document.getElementById('HeaderBack').click()");

                driver.ForceSleep(m_sleepTime);
            }
        }