Beispiel #1
0
        public CSoccerGameUpdate ParseBasicGameDetails(HtmlNode node, DateTime date)
        {
            var game = new CSoccerGameUpdate();

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

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

            if (!string.IsNullOrEmpty(rawScore))
            {
                var scores = ParseScore(rawScore);
                game.HomeTeam.Competitor.Scores[(int)ESoccerStages.CurrResult] = scores[0];
                game.AwayTeam.Competitor.Scores[(int)ESoccerStages.CurrResult] = scores[1];
            }

            if (!string.IsNullOrEmpty(rawGameStartTime))
            {
                var time = ParseFunctions.ParseTime(rawGameStartTime);
                game.StartTime = date.Date.Add(time).Subtract(DataFetcher.TimeOffset);
            }
            else
            {
                game.StartTime = date.Date.AddHours(16);
            }

            return(game);
        }
        public async Task BuildGameFullDetails(string gameUrl, ScanMetaData scanMetaData)
        {
            scanMetaData.Update = scanMetaData.Update ?? new CSoccerGameUpdate()
            {
                CreateGame = false
            };

            CSoccerGameUpdate gameUpdate = scanMetaData.Update;

            try
            {
                var fetchResult = await _dataFetcher.FetchDom(string.Format(BASE_URL, gameUrl));

                var doc = fetchResult.HtmlDocument;

                scanMetaData.JsonGameRequestCode = GetJsonGameRequestCode(doc);
                if (string.IsNullOrWhiteSpace(scanMetaData.JsonGameRequestCode))
                {
                    SetTeamsLineups(doc, gameUpdate);
                    SetTeamsSubsEvents(doc, gameUpdate);
                }
            }
            catch (Exception ex)
            {
            }
        }
Beispiel #3
0
        public IDictionary <string, CSoccerGameUpdate> ParseGameList(HtmlDocument doc, DateTime date)
        {
            var gamesDictionary = new Dictionary <string, CSoccerGameUpdate>();

            var rawGames = doc.DocumentNode.SelectNodes("//tr[contains(@class,'match')]/.");

            foreach (var rawGame in rawGames)
            {
                try
                {
                    CSoccerGameUpdate game = ParseBasicGameDetails(rawGame, date);
                    if (game != null)
                    {
                        string gameUri = ParseGameUri(rawGame);

                        string leaguePath = new StringBuilder().Append(rawGame.XPath).Append("/preceding-sibling::tr[contains(@class,'round-head') or contains(@class,'group-head')]").ToString();
                        string midComp    = string.Empty;

                        if (!string.IsNullOrEmpty(gameUri) && !gamesDictionary.ContainsKey(gameUri))
                        {
                            HtmlNodeCollection leagueParent = null;
                            try
                            {
                                leagueParent = rawGame.SelectNodes(leaguePath);
                            }
                            catch (Exception ex)
                            {
                            }
                            if (leagueParent != null)
                            {
                                HtmlNode midCompNode = leagueParent.LastOrDefault();
                                if (midCompNode.Attributes["class"].Value.Contains("round-head"))
                                {
                                    midComp = ExtractMidCompetitionName(midCompNode);
                                }
                            }
                            game.Competition.Value = midComp;
                            gamesDictionary.Add(gameUri, game);
                        }
                    }
                }
                catch (Exception ex)
                {
                }
            }

            return(gamesDictionary);
        }
Beispiel #4
0
        public CSoccerGameUpdate ParseGameGoals(HtmlNodeCollection matchEventsCollectionRaw, CSoccerGameUpdate game)
        {
            // Select evnet rows
            if (matchEventsCollectionRaw != null && matchEventsCollectionRaw.Count > 0)
            {
                int goalCount = 1;
                foreach (HtmlAgilityPack.HtmlNode gameEventRaw in matchEventsCollectionRaw)
                {
                    try
                    {
                        // Select team event
                        HtmlAgilityPack.HtmlNode[] goalListRaw = new HtmlAgilityPack.HtmlNode[]
                        { gameEventRaw.SelectSingleNode("td[@class='player player-a']"),
                          gameEventRaw.SelectSingleNode("td[@class='player player-b']") };


                        CSportTypedCompetitorInGame <ESoccerStages> team = null;

                        for (int teamId = 0; teamId < 2; teamId++)
                        {
                            var eventRow = goalListRaw[teamId];

                            if (teamId == 0)
                            {
                                team = game.HomeTeam;
                            }
                            else
                            {
                                team = game.AwayTeam;
                            }

                            /*
                             * if (eventRow != null)
                             * {
                             *  LocalGameEvent goalEvent = ParseFunctions.ParseGoalEvent(eventRow);
                             *
                             *  if (goalEvent.PlayerData != null && !string.IsNullOrEmpty(goalEvent.PlayerData.Name))
                             *  {
                             *      goalCount++;
                             *      game.AddEvent(
                             *          ESoccerEventTypes.Goal, goalCount,
                             *          team,
                             *          (int)goalEvent.GoalSubType,
                             *          (int)goalEvent.GameTime, goalEvent.PlayerData.Name
                             *          );
                             *  }
                             * }*/
                        }
                    }
                    catch (Exception ex)
                    {
                    }
                }
            }


            return(game);
        }
Beispiel #5
0
        public async Task <CSoccerGameUpdate> BuildGameEvents(int gameId, DateTime date, CSoccerGameUpdate game)
        {
            var url = string.Format(DateTime.UtcNow.Date > date.Date ? URL_EVENTS_PAST : URL_EVENTS, date.ToString(MatchesDateFormat), gameId);

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

            var matchEventsCollectionRaw = fetchResult.HtmlDocument.DocumentNode.SelectNodes("//tr[contains(@class,'event')]/.");

            game = ParseGameGoals(matchEventsCollectionRaw, game);

            return(game);
        }
 private void SetTeamsLineups(HtmlDocument doc, CSoccerGameUpdate gameUpdate)
 {
     SetHomeTeamLineup(doc, gameUpdate.HomeTeam.Competitor);
     SetAwayTeamLineup(doc, gameUpdate.AwayTeam.Competitor);
 }
 private void SetTeamsSubsEvents(HtmlDocument doc, CSoccerGameUpdate gameUpdate)
 {
     SetHomeTeamSubsEvents(doc, gameUpdate.HomeTeam.Competitor);
     SetAwayTeamSubsEvents(doc, gameUpdate.AwayTeam.Competitor);
 }