コード例 #1
0
        public static MockDraftPick CreateMockDraftEntry(HtmlNode tableRow, string pickDate)
        {
            var    childNodes = tableRow.ChildNodes;
            var    node1      = childNodes[1].InnerText; //pick number?
            string pickNumber = node1.Replace("\r", "")
                                .Replace("\n", "")
                                .Replace("\t", "")
                                .Replace(" ", "");
            var node3    = childNodes[3]; //team (and team image)?
            var teamCity = node3.ChildNodes[0].InnerText
                           .Replace("\r", "")
                           .Replace("\n", "")
                           .Replace("\t", "")
                           .TrimEnd();
            var    node5      = childNodes[5]; //Has Child Nodes - Player, School, Position, Reach/Value
            string playerName = node5.ChildNodes[1].InnerText
                                .Replace("\r", "")
                                .Replace("\n", "")
                                .Replace("\t", "")
                                .TrimEnd();
            string playerSchoolBeforeChecking = node5.ChildNodes[3].InnerText
                                                .Replace("\r", "")
                                                .Replace("\n", "")
                                                .Replace("\t", "")
                                                .TrimEnd(); // this may have a space afterwards.
            string playerSchool   = School.CheckSchool(playerSchoolBeforeChecking);
            string playerPosition = node5.ChildNodes[5].InnerText
                                    .Replace("\r", "")
                                    .Replace("\n", "")
                                    .Replace("\t", "")
                                    .Replace(" ", "");
            string reachValue = node5.ChildNodes[9].InnerText
                                .Replace("\r", "")
                                .Replace("\n", "")
                                .Replace("\t", "")
                                .Replace(" ", "");

            var mdp = new MockDraftPick()
            {
                Pick       = int.Parse(pickNumber),
                PickNumber = pickNumber,
                TeamCity   = teamCity,
                PlayerName = playerName,
                School     = playerSchool,
                Position   = playerPosition,
                ReachValue = reachValue,
                PickDate   = pickDate
            };

            File.AppendAllText($"logs{Path.DirectorySeparatorChar}Prospects.log", "Mock Draft Round: " + mdp.Round + Environment.NewLine);
            File.AppendAllText($"logs{Path.DirectorySeparatorChar}Prospects.log", "Pick Number: " + mdp.PickNumber + Environment.NewLine);
            File.AppendAllText($"logs{Path.DirectorySeparatorChar}Prospects.log", "Player: " + mdp.PlayerName + Environment.NewLine);
            return(mdp);
        }
コード例 #2
0
        public static List <ProspectRanking> GetProspects(HtmlDocument document, DateTime dateOfRanks, int pageNumber)
        {
            var prospectList = new List <ProspectRanking>();

            if (document.DocumentNode != null)
            {
                var tbl = document.DocumentNode.SelectNodes("/html[1]/body[1]/div[1]/div[3]/div[1]/table[1]");

                if (tbl == null)
                {
                    File.AppendAllText($"logs{Path.DirectorySeparatorChar}Status.log", $"No prospects on page {pageNumber}" + Environment.NewLine);
                    return(prospectList);
                }

                // Create variables to store prospect rankings.
                int    rank         = 0;
                string change       = "";
                string playerName   = "";
                string school       = "";
                string position1    = "";
                string height       = "";
                int    weight       = 0;
                string collegeClass = "";

                foreach (HtmlNode table in tbl)
                {
                    foreach (HtmlNode row in table.SelectNodes("tr"))
                    {
                        foreach (HtmlNode cell in row.SelectNodes("th|td"))
                        {
                            string Xpath = cell.XPath;
                            int    locationOfColumnNumber = cell.XPath.Length - 2;
                            char   dataIndicator          = Xpath[locationOfColumnNumber];
                            bool   isRank = (dataIndicator == '1');
                            switch (dataIndicator)
                            {
                            case '1':
                                // td[1]= Rank
                                if (Int32.TryParse(cell.InnerText, out int rankNumber))
                                {
                                    rank = rankNumber;
                                }
                                File.AppendAllText($"logs{Path.DirectorySeparatorChar}Prospects.log", "Big Board Rank: " + cell.InnerText + Environment.NewLine);
                                break;

                            case '2':
                                // td[2]= Change
                                change = cell.InnerText;
                                change = change.Replace("&nbsp;", "");
                                break;

                            case '3':
                                // td[3]= Player
                                playerName = cell.InnerText;
                                File.AppendAllText($"logs{Path.DirectorySeparatorChar}Prospects.log", "Player: " + cell.InnerText + Environment.NewLine);
                                break;

                            case '4':
                                // td[4]= School
                                school = School.CheckSchool(cell.InnerText);
                                break;

                            case '5':
                                // td[5]= Pos1
                                position1 = cell.InnerText;
                                break;

                            case '6':
                                // td[6]= Ht
                                height = cell.InnerText;
                                break;

                            case '7':
                                // td[7]= Weight
                                if (Int32.TryParse(cell.InnerText, out int weightNumber))
                                {
                                    weight = weightNumber;
                                }
                                break;

                            case '8':
                                // College Class- used to be Pos2 (which was often blank)
                                collegeClass = cell.InnerText;
                                break;

                            case '9':
                                // td[9]= Link to Bio (not used)
                                continue;

                            default:
                                break;
                            }
                        }
                        // Handle draft eligibility and declarations (done via row color)
                        string draftStatus = "";
                        if (row.Attributes.Contains("style") && row.Attributes["style"].Value.Contains("background-color"))
                        {
                            string rowStyle        = row.Attributes["style"].Value;
                            string backgroundColor = Regex.Match(rowStyle, @"background-color: \w*").Value.Substring(18);
                            draftStatus = backgroundColor switch
                            {
                                "white" => "Eligible",
                                "lightblue" => "Underclassman",
                                "palegoldenrod" => "Declared",
                                _ => "",
                            };
                            File.AppendAllText($"logs{Path.DirectorySeparatorChar}Prospects.log", "Draft Status: " + draftStatus + Environment.NewLine);
                        }
                        // The header is in the table, so I need to ignore it here.
                        if (change != "CNG")
                        {
                            prospectList.Add(new ProspectRanking(dateOfRanks, rank, change, playerName, school, position1, height, weight, collegeClass, draftStatus));
                        }
                    }
                }
                File.AppendAllText($"logs{Path.DirectorySeparatorChar}Status.log", $"Prospect count on page {pageNumber}: {prospectList.Count}" + Environment.NewLine);
            }
            return(prospectList);
        }