Ejemplo n.º 1
0
        /// <summary>
        /// Locates a horse by its name.
        /// </summary>
        /// <param name="name">The name of the horse to find.</param>
        /// <returns>Information about the horse if an exact match is found or null if not.</returns>
        public Horse FindHorse(string name)
        {
            if (string.IsNullOrWhiteSpace(name))
            {
                throw new ArgumentException("name", "A valid horse name must be specified.");
            }

            var result    = ExecuteHorseSearch(name);
            var id        = ExtractHorseIdFromSearchResults(name, result);
            var horsePage = GetHorsePage(id);

            var document = new HtmlAgilityPack.HtmlDocument();
            var horse    = new Horse();

            // <div class="popUp"><div class="popUpHead clearfix"><div class="leftCol"><h1>Academy General (IRE)  <span>Race record</span></h1>
            document.LoadHtml(horsePage);
            var nameNode  = document.DocumentNode.SelectSingleNode("//div[@class='popUp']/div[@class='popUpHead clearfix']/div[@class='leftCol']/h1");
            var horseName = nameNode.ChildNodes[0].InnerText.Trim();

            Regex horseNameRegex = new Regex(@"^([^\(]+)( \((.+)\))?$");
            var   horseNameMatch = horseNameRegex.Match(horseName);

            horse.Name = horseNameMatch.Groups[1].Value;
            var capturedName = horseNameMatch.Groups[3].Value;

            horse.CountryOfBirth = string.IsNullOrWhiteSpace(capturedName) ? "GBR" : capturedName;

            /* ==Date of Birth, Mother, Father==
             * <ul id="detailedInfo">
             * <li>
             * <b>
             * 7-y-o (17Apr06 b g)
             * </b>
             * </li>
             * <li>
             * <b>
             * <a href="http://bloodstock.racingpost.com/stallionbook/stallion.sd?horse_id=75837&amp;popup=1" class="White" onclick='scorecards.send("stallion_name");return Html.popup(this, {width:750, height:800})' title="Full details about this STALLION">Beneficial </a> </b>
             * &nbsp;(14.3f) —
             * <b>
             * <a href="http://bloodstock.racingpost.com/dam/dam_home.sd?horse_id=503103" class="White" onclick='scorecards.send("dam_name");return Html.popup(this, {width:695, height:800})' title="Full details about this DAM ">Discerning Air </a> </b>
             * (<b><a href="http://bloodstock.racingpost.com/stallionbook/stallion.sd?horse_id=69582&amp;popup=1" class="White" onclick='scorecards.send("stallion_name");return Html.popup(this, {width:750, height:800})' title="Full details about this STALLION">Ezzoud (IRE)</a></b>
             * &nbsp;<span>(11.5f)</span>)
             * </li>
             */
            var dobNode = document.DocumentNode.SelectSingleNode("//ul[@id='detailedInfo']/li/b");
            var dobText = dobNode.InnerText.Trim();

            var dobRegex = new Regex(@"\((\d+)([A-Za-z]+)(\d+) .*\)");
            var dobMatch = dobRegex.Match(dobText);

            horse.DateOfBirth = DateTime.Parse(string.Format("{0}-{1}-{2}", dobMatch.Groups[1], dobMatch.Groups[2], dobMatch.Groups[3]));

            var parentageNodes = document.DocumentNode.SelectNodes("//ul[@id='detailedInfo']//li//b/a[@class='White']");

            var fatherText = parentageNodes[0].InnerText.Trim();

            horse.father = new Lazy <Horse>(() => FindHorse(fatherText));

            var motherText = parentageNodes[1].InnerText.Trim();

            horse.mother = new Lazy <Horse>(() => FindHorse(motherText));

            // Breed => Load Pedigree tab: http://www.racingpost.com/horses/horse_pedigree.sd?horse_id={id}

            // Form
            // <div id="horse_race_record" class="tabContent tabSelected"><p class="border">Jumps placings 9/9<b>P</b><b>F</b><b>6</b><b>5</b><b>3</b>/<b>U</b><b>3</b>-</p>


            return(horse);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Locates a horse by its name.
        /// </summary>
        /// <param name="name">The name of the horse to find.</param>
        /// <returns>Information about the horse if an exact match is found or null if not.</returns>
        public Horse FindHorse(string name)
        {
            if (string.IsNullOrWhiteSpace(name)) {
            throw new ArgumentException("name", "A valid horse name must be specified.");
              }

              var result = ExecuteHorseSearch(name);
              var id = ExtractHorseIdFromSearchResults(name, result);
              var horsePage = GetHorsePage(id);

              var document = new HtmlAgilityPack.HtmlDocument();
              var horse = new Horse();

              // <div class="popUp"><div class="popUpHead clearfix"><div class="leftCol"><h1>Academy General (IRE)  <span>Race record</span></h1>
              document.LoadHtml(horsePage);
              var nameNode = document.DocumentNode.SelectSingleNode("//div[@class='popUp']/div[@class='popUpHead clearfix']/div[@class='leftCol']/h1");
              var horseName = nameNode.ChildNodes[0].InnerText.Trim();

              Regex horseNameRegex = new Regex(@"^([^\(]+)( \((.+)\))?$");
              var horseNameMatch = horseNameRegex.Match(horseName);
              horse.Name = horseNameMatch.Groups[1].Value;
              var capturedName = horseNameMatch.Groups[3].Value;
              horse.CountryOfBirth = string.IsNullOrWhiteSpace(capturedName) ? "GBR" : capturedName;

              /* ==Date of Birth, Mother, Father==
               * <ul id="detailedInfo">
               * <li>
               * <b>
               * 7-y-o (17Apr06 b g)
               * </b>
               * </li>
               * <li>
               * <b>
               * <a href="http://bloodstock.racingpost.com/stallionbook/stallion.sd?horse_id=75837&amp;popup=1" class="White" onclick='scorecards.send("stallion_name");return Html.popup(this, {width:750, height:800})' title="Full details about this STALLION">Beneficial </a> </b>
               * &nbsp;(14.3f) —
               * <b>
               * <a href="http://bloodstock.racingpost.com/dam/dam_home.sd?horse_id=503103" class="White" onclick='scorecards.send("dam_name");return Html.popup(this, {width:695, height:800})' title="Full details about this DAM ">Discerning Air </a> </b>
               * (<b><a href="http://bloodstock.racingpost.com/stallionbook/stallion.sd?horse_id=69582&amp;popup=1" class="White" onclick='scorecards.send("stallion_name");return Html.popup(this, {width:750, height:800})' title="Full details about this STALLION">Ezzoud (IRE)</a></b>
               * &nbsp;<span>(11.5f)</span>)
               * </li>
               */
              var dobNode = document.DocumentNode.SelectSingleNode("//ul[@id='detailedInfo']/li/b");
              var dobText = dobNode.InnerText.Trim();

              var dobRegex = new Regex(@"\((\d+)([A-Za-z]+)(\d+) .*\)");
              var dobMatch = dobRegex.Match(dobText);
              horse.DateOfBirth = DateTime.Parse(string.Format("{0}-{1}-{2}", dobMatch.Groups[1], dobMatch.Groups[2], dobMatch.Groups[3]));

              var parentageNodes = document.DocumentNode.SelectNodes("//ul[@id='detailedInfo']//li//b/a[@class='White']");

              var fatherText = parentageNodes[0].InnerText.Trim();
              horse.father = new Lazy<Horse>(() => FindHorse(fatherText));

              var motherText = parentageNodes[1].InnerText.Trim();
              horse.mother = new Lazy<Horse>(() => FindHorse(motherText));

              // Breed => Load Pedigree tab: http://www.racingpost.com/horses/horse_pedigree.sd?horse_id={id}

              // Form
              // <div id="horse_race_record" class="tabContent tabSelected"><p class="border">Jumps placings 9/9<b>P</b><b>F</b><b>6</b><b>5</b><b>3</b>/<b>U</b><b>3</b>-</p>

              return horse;
        }