Ejemplo n.º 1
0
        private static List <PowerRanking> GetPowerRankings(ChromeDriver driver, WeekRepository weekRepository)
        {
            var currentWeek           = week;
            var weeksForPowerRankings = new List <Week>();

            for (var i = 3; i >= 0; i--)
            {
                if (currentWeek - i > 0)
                {
                    weeksForPowerRankings.Add(weekRepository.GetWeek(driver, currentWeek - i, year));
                }
            }

            var powerRankingGenerator = new PowerRankingGenerator(weeksForPowerRankings, currentWeek);

            return(powerRankingGenerator.GeneratePowerRankings());
        }
Ejemplo n.º 2
0
        private static void Main(string[] args)
        {
            var options = new ChromeOptions();
            //options.AddArgument("--headless");
            var driver = new ChromeDriver(options);

            //new ReturnerBuilder(driver).GenerateReturners();

            //login

            driver.Navigate().GoToUrl($"http://games.espn.com/ffl/standings?leagueId=127291&seasonId={year}");
            driver.SwitchTo().Frame("disneyid-iframe");
            var userNameBox = driver.FindElement(By.CssSelector("div.field-username-email input"));

            userNameBox.SendKeys(Keys.ArrowDown);
            userNameBox.SendKeys("*****@*****.**");

            var passwordBox = driver.FindElement(By.CssSelector("div.field-password input"));

            passwordBox.SendKeys(Keys.ArrowDown);
            passwordBox.SendKeys("grip1334");
            passwordBox.SendKeys(Keys.Enter);
            Thread.Sleep(2000);

            driver.Manage().Timeouts().PageLoad = new TimeSpan(0, 0, 0, 5);

            //var rmlPlayerBuilder = new RmlPlayerBuilder(driver, 2018);
            //var rmlPlayers = rmlPlayerBuilder.BuildRmlPlayers();
            //var rmlPlayerRepository = new RmlPlayerRepository();

            //rmlPlayerRepository.RefreshRmlPlayers(rmlPlayers);

            //var rmlPlayers = rmlPlayerRepository.GetRmlPlayers();

            //var sitePlayerBuilder = new SitePlayerBuilder(driver);
            //var sitePlayers = sitePlayerBuilder.BuildSitePlayers();
            //sitePlayerRepository.RefreshSitePlayers(sitePlayers);

            //var sitePlayerRepository = new SitePlayerRepository();
            //var sitePlayers = sitePlayerRepository.GetSitePlayers();

            //Console.WriteLine("Writing returner File:");
            //new PrintPlayerComparerService(sitePlayers.OrderBy(p => p.Name).ToList(), rmlPlayers).WritePlayerComparerFile();
            //Console.WriteLine("Writing returner File COMPLETE");

            //postDraftRankings
            //var postDraftRankingGenerator = new PostDraftRankingGenerator(driver);
            //postDraftRankingGenerator.GenerateRankings();

            //driver.Manage().Timeouts().PageLoad = new TimeSpan(0, 0, 0, 5);

            //get teams
            //var teamBuilder = new TeamBuilder(driver, year);
            //var teamRepository = new TeamRepository();

            //var teams = teamBuilder.BuildTeams();
            //teamRepository.RefreshTeams(teams);
            //var teams = teamRepository.GetTeams();

            driver.WaitUntilElementExists(By.CssSelector("table.tableBody"));

            //OPS
            driver.Navigate().GoToUrl($"http://games.espn.com/ffl/freeagency?leagueId=127291&seasonId={year}");
            driver.WaitUntilElementExists(By.Id("playerTableContainerDiv"));

            var opLink = driver.FindElement(By.XPath("//ul[@class='filterToolsOptionSet']/li/a[contains(.,'OP')]"));

            opLink.Click();

            Thread.Sleep(2000);

            var onRosterLink = driver.FindElement(By.XPath("//ul[@class='filterToolsOptionSet']/li/a[contains(.,'On Rosters')]"));

            onRosterLink.Click();

            Thread.Sleep(2000);

            var lastLink = driver.FindElement(By.XPath("//tr[contains(@class, 'playerTableBgRowSubhead')]/td/a[contains(.,'LAST')]"));

            lastLink.Click();

            Thread.Sleep(5000);

            var opRows       = driver.FindElements(By.XPath("//tr[contains(@class, 'pncPlayerRow')]/td[3][not(contains(.,'FA'))]/parent::tr"));
            var opsOfTheWeek = new List <PlayerOfTheWeek>();
            var topPoints    = 0m;

            foreach (var opRow in opRows)
            {
                var rowPoints = decimal.Parse(opRow.FindElement(By.XPath("./td[contains(@class, 'sortedCell')]")).Text);
                if (rowPoints >= topPoints)
                {
                    topPoints = rowPoints;
                }
                else
                {
                    break;
                }

                var opOfTheWeek = new PlayerOfTheWeek();
                opOfTheWeek.Name             = opRow.FindElement(By.XPath("./td[@class='playertablePlayerName']/a")).Text;
                opOfTheWeek.Team             = opRow.FindElement(By.XPath("./td[3]/a")).GetAttribute("title");
                opOfTheWeek.TeamAbbreviation = opRow.FindElement(By.XPath("./td[3]/a")).Text;
                opOfTheWeek.PlayerId         = int.Parse(opRow.FindElement(By.XPath("./td[@class='playertablePlayerName']/a")).GetAttribute("playerid"));
                opOfTheWeek.Points           = rowPoints;

                opRow.FindElement(By.XPath("./td[@class='playertablePlayerName']/a")).Click();
                Thread.Sleep(2000);
                opOfTheWeek.TeamAgainstAbbreviation = driver.FindElement(By.XPath($"//div[@id='pcBorder']/table/tbody/tr[{week + 1}]/td[2]/a")).Text;

                driver.FindElement(By.XPath("//img[@id='fpop_closebtn']")).Click();
                Thread.Sleep(500);

                opsOfTheWeek.Add(opOfTheWeek);
            }

            //DPS
            var dpLink = driver.FindElement(By.XPath("//ul[@class='filterToolsOptionSet']/li/a[contains(.,'DP')]"));

            dpLink.Click();

            Thread.Sleep(2000);

            var dpRows       = driver.FindElements(By.XPath("//tr[contains(@class, 'pncPlayerRow')]/td[3][not(contains(.,'FA'))]/parent::tr"));
            var dpsOfTheWeek = new List <PlayerOfTheWeek>();

            topPoints = 0m;
            foreach (var dpRow in dpRows)
            {
                var rowPoints = decimal.Parse(dpRow.FindElement(By.XPath("./td[contains(@class, 'sortedCell')]")).Text);
                if (rowPoints >= topPoints)
                {
                    topPoints = rowPoints;
                }
                else
                {
                    break;
                }

                var dpOfTheWeek = new PlayerOfTheWeek();
                dpOfTheWeek.Name             = dpRow.FindElement(By.XPath("./td[@class='playertablePlayerName']/a")).Text;
                dpOfTheWeek.Team             = dpRow.FindElement(By.XPath("./td[3]/a")).GetAttribute("title");
                dpOfTheWeek.TeamAbbreviation = dpRow.FindElement(By.XPath("./td[3]/a")).Text;
                dpOfTheWeek.PlayerId         = int.Parse(dpRow.FindElement(By.XPath("./td[@class='playertablePlayerName']/a")).GetAttribute("playerid"));
                dpOfTheWeek.Points           = rowPoints;

                dpRow.FindElement(By.XPath("./td[@class='playertablePlayerName']/a")).Click();
                Thread.Sleep(2000);
                dpOfTheWeek.TeamAgainstAbbreviation = driver.FindElement(By.XPath($"//div[@id='pcBorder']/table/tbody/tr[{week + 1}]/td[2]/a")).Text;

                driver.FindElement(By.XPath("//img[@id='fpop_closebtn']")).Click();
                Thread.Sleep(500);

                dpsOfTheWeek.Add(dpOfTheWeek);
            }

            var weekRepository = new WeekRepository();
            var powerRankings  = GetPowerRankings(driver, weekRepository);
            var currentWeek    = weekRepository.GetWeek(driver, week, year);

            var weeklyPayoutTeams = string.Empty;

            for (var i = 1; i <= week; i++)
            {
                var weekForWeeklyPayouts  = weekRepository.GetWeek(driver, i, year);
                var teamsForWeeklyPayouts = weekForWeeklyPayouts.Scores.Select(s => s.AwayTeam).ToList();
                teamsForWeeklyPayouts.AddRange(weekForWeeklyPayouts.Scores.Select(s => s.HomeTeam));
                weeklyPayoutTeams += i + ". " + teamsForWeeklyPayouts.OrderByDescending(t => t.TeamPoints).First().TeamName.ToUpper() + @"
                ";
            }

            List <ITrophy> trophies = new List <ITrophy>();

            //Console.WriteLine("Do you want to assign trophies? (Y/N[default])");
            //var assignTrophiesInput = Console.ReadLine();

            //if (assignTrophiesInput == "Y")
            //{
            trophies = AssignTrophies(currentWeek, opsOfTheWeek, dpsOfTheWeek, driver);
            //}

            CreateLeaguePage(powerRankings, weeklyPayoutTeams, trophies, currentWeek, week);
            var x = 1;
        }