Example #1
0
        public async Task <Dictionary <int, string> > GetNationalCountries()
        {
            var fetchResult = await _dataFetcher.FetchDom(URL_NATIONAL);

            var allCountries = new Dictionary <int, string>();

            var countryList = fetchResult.HtmlDocument.DocumentNode.SelectNodes("//li[contains(@class,'expandable')]/.");

            foreach (var country in countryList)
            {
                try
                {
                    var areaId = country.GetAttributeValue("data-area_id", "");
                    if (!string.IsNullOrWhiteSpace(areaId))
                    {
                        var countryId   = ParseFunctions.ParsePositiveNumber(areaId);
                        var countryName = HttpUtility.HtmlDecode(country.InnerText).Trim();
                        if (!allCountries.ContainsKey(countryId))
                        {
                            allCountries.Add(countryId, countryName);
                        }
                    }
                }
                catch (Exception exception)
                {
                }
            }

            return(allCountries);
        }
        public async Task <List <CompetitorData> > BuildCompetitorsListByCompetition(CompetitionData comptition)
        {
            var competitorList = new List <CompetitorData>();

            try
            {
                var param = string.Format(API_ExtraParam,
                                          HttpUtility.UrlEncode(string.Format(Competitions_CallbackParam, 2)),
                                          Competitions_Action,
                                          HttpUtility.UrlEncode(string.Format(Competitors_Param, comptition.ID)));

                var url = string.Format(ApiFormat, BASE_API_URL, Competitions_Block, param);

                var fetchResult = await _dataFetcher.FetchDom(url, true);

                var rawComptitor = fetchResult.HtmlDocument.DocumentNode.SelectNodes("//ul/li/.");
                if (rawComptitor != null)
                {
                    foreach (var rawComp in rawComptitor)
                    {
                        try
                        {
                            var rawLink = rawComp.SelectSingleNode(rawComp.XPath + "//a/.");

                            var link = rawLink.GetAttributeValue("href", "");
                            if (string.IsNullOrEmpty(link))
                            {
                            }
                            else
                            {
                                var comp = new CompetitorData
                                {
                                    Link            = link,
                                    Id              = ParseFunctions.ParsePositiveNumber(link, "/(?<num>\\d{2,})"),
                                    Name            = HttpUtility.HtmlDecode(rawLink.InnerText),
                                    CompetitionData = comptition
                                };

                                competitorList.Add(comp);
                            }
                        }
                        catch (Exception ex)
                        {
                        }
                    }
                }
            }
            catch (Exception exception)
            {
            }

            return(competitorList);
        }
        private List <CompetitorData> ParseBasicGameDetails(HtmlNode node, DateTime date)
        {
            List <CompetitorData> game = null;

            try
            {
                var home = new CompetitorData();
                var away = new CompetitorData();

                home.Name = ParseFunctions.ExtractValueFromNode(node, "//td[@class='team team-a ']/a/.", "title");
                away.Name = ParseFunctions.ExtractValueFromNode(node, "//td[@class='team team-b ']/a/.", "title");

                home.Link = ParseFunctions.ExtractValueFromNode(node, "//td[@class='team team-a ']/a/.", "href");
                away.Link = ParseFunctions.ExtractValueFromNode(node, "//td[@class='team team-b ']/a/.", "href");

                home.Id = ParseFunctions.ParsePositiveNumber(home.Link, "/(?<num>\\d{2,})");
                away.Id = ParseFunctions.ParsePositiveNumber(away.Link, "/(?<num>\\d{2,})");

                var rawGameStartTime = ParseFunctions.ExtractValueFromNode(node, "//td[@class='score-time status']");
                var rawScore         = ParseFunctions.ExtractValueFromNode(node, "//td[@class='score-time score']");

                if (!string.IsNullOrEmpty(rawGameStartTime))
                {
                    var time        = ParseFunctions.ParseTime(rawGameStartTime);
                    var gameTime    = date.Date.Add(time).Subtract(DataFetcher.TimeOffset);
                    var scanContext = new ScanContext(gameTime);
                    home.NextScan = scanContext;
                    away.NextScan = scanContext;
                }
                else
                {
                    var gameTime    = date.Date.AddHours(16);
                    var scanContext = new ScanContext(gameTime);
                    home.NextScan = scanContext;
                    away.NextScan = scanContext;
                }

                game = new List <CompetitorData>()
                {
                    home, away
                };
            }
            catch (Exception exception)
            {
            }

            return(game);
        }