Esempio n. 1
0
        public static bool GetField(string League, string Trigger, int HistoricalSeasonID, string SeasonTypeId, string Command)
        {
            var st            = new StackTrace();
            var sf            = st.GetFrame(0);
            var currentMethod = sf.GetMethod();
            var thisFile      = new System.Diagnostics.StackTrace(true).GetFrame(0).GetFileName();


            var web       = new HtmlWeb();
            var playerWeb = new HtmlWeb();
            var doc       = web.Load(Fetch.GetURL(League, Trigger, HistoricalSeasonID, SeasonTypeId));

            #region Player count calculator

            var countPlayers = doc.DocumentNode.SelectNodes("//*[@id='lgtable_memberstats51']/tbody/tr");
            if (countPlayers == null)
            {
                return(false);
            }
            var playerCount = countPlayers.Count;
            #endregion

            #region Player stat parser

            try
            {
                for (int i = 1; i < playerCount; i++)
                {
                    var findPlayerNodes = doc.DocumentNode.SelectNodes($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]");
                    if (findPlayerNodes == null)
                    {
                        break;
                    }
                    foreach (var player in findPlayerNodes)
                    {
                        var teamIconTemp      = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[2]/img").Attributes["src"].Value);
                        var position          = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[2]/span").InnerText);
                        var playerName        = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[2]/a").InnerText);
                        var gamesPlayed       = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[4]").InnerText);
                        var record            = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[5]").InnerText);
                        var avgMatchRating    = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[6]").InnerText);
                        var goals             = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[7]").InnerText);
                        var assists           = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[8]").InnerText);
                        var cleanSheets       = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[9]").InnerText);
                        var shotsOnGoal       = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[10]").InnerText);
                        var shotsOnTarget     = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[11]").InnerText);
                        var shotPercentage    = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[12]").InnerText);
                        var tackles           = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[13]").InnerText);
                        var tackleAttempts    = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[14]").InnerText);
                        var tacklePercentage  = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[15]").InnerText);
                        var passingPercentage = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[16]").InnerText);
                        var keyPasses         = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[17]").InnerText);
                        var interceptions     = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[18]").InnerText);
                        var blocks            = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[19]").InnerText);
                        var yellowCards       = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[20]").InnerText);
                        var redCards          = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[21]").InnerText);
                        var manOfTheMatch     = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[22]").InnerText);
                        var playerShortURL    = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[2]/a").Attributes["href"].Value);

                        var playerURL   = string.Join(string.Empty, "https://www.leaguegaming.com/forums/" + playerShortURL);
                        var iconEnlarge = teamIconTemp.Replace("p16", "p100");
                        var iconURL     = string.Join(string.Empty, "https://www.leaguegaming.com" + iconEnlarge);
                        var temp        = HttpUtility.ParseQueryString(new Uri(playerURL).Query);
                        int playerId    = int.Parse(temp.Get("userid"));

                        if (shotPercentage == String.Empty)
                        {
                            shotPercentage = "0";
                        }
                        if (tacklePercentage == string.Empty)
                        {
                            tacklePercentage = "0";
                        }
                        if (passingPercentage == String.Empty)
                        {
                            passingPercentage = "0";
                        }

                        if (SeasonTypeId == "pre")
                        {
                            SeasonTypeId = "pre-season";
                        }
                        else if (SeasonTypeId == "reg")
                        {
                            SeasonTypeId = "regular";
                        }

                        Tools.DataSaver.SavePlayerUrl(playerId, playerName, playerURL);
                        //Console.WriteLine($"Saved {playerName} url. PLayerEngine");

                        CareerEngine.GetCareer(playerId, playerName, League);
                        //Console.WriteLine($"{playerName}, career saved PLayerEngine");

                        Tools.DataSaver.Save(playerId, HistoricalSeasonID, SeasonTypeId, position,
                                             playerName, gamesPlayed, record, avgMatchRating, goals, assists, cleanSheets, shotsOnGoal,
                                             shotsOnTarget, shotPercentage, tackles, tackleAttempts, tacklePercentage, passingPercentage, keyPasses,
                                             interceptions, blocks, yellowCards, redCards, manOfTheMatch, playerURL, League, iconURL, Command);
                    }
                }
                return(true);
            }
            catch (Exception e)
            {
                Log.Logger.Error(e, $"Error processing Player Stats {currentMethod}");
                return(false);
            }
            #endregion
        }
Esempio n. 2
0
        public static bool GetTeam(string System, string Trigger, int SeasonId, string SeasonTypeId, string Command)
        {
            var web = new HtmlWeb();
            var doc = web.Load(Fetch.GetURL(System, Trigger, SeasonId, SeasonTypeId));

            var findRankNodes = doc.DocumentNode.SelectNodes("//*[@style = 'overflow:hidden;padding:0px;']").ToList();
            var rank          = "";
            var teamName      = "";
            var teamIndex     = 1;
            var gamesPlayed   = "";
            var gamesWon      = "";
            var gamesDrawn    = "";
            var gamesLost     = "";
            var points        = "";
            var streak        = "";
            var goalsFor      = "";
            var goalsAgainst  = "";
            var cleanSheets   = "";
            var lastTenGames  = "";
            var homeRecord    = "";
            var awayRecord    = "";
            var oneGoalGames  = "";
            var teamIconUrl   = "";
            var teamUrl       = "";
            var teamID        = "";

            try
            {
                foreach (var team in findRankNodes)
                {
                    #region Splits Team Rank & name into 2 variables

                    var      tempRank  = team.InnerText;
                    string[] splitRank = tempRank.Split(' ');
                    if (splitRank.Length > 3)
                    {
                        var split = tempRank.Split(new[] { ' ' }, 3);
                        rank     = split[1];
                        teamName = split[2];
                    }
                    else
                    {
                        rank     = splitRank[1];
                        teamName = splitRank[2];
                    }

                    #endregion

                    gamesPlayed = team.NextSibling.NextSibling.InnerText;
                    gamesWon    = team.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                    gamesDrawn  = team.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                    gamesLost   = team.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                  .NextSibling.InnerText;
                    points = team.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                             .NextSibling.NextSibling.NextSibling.InnerText;
                    streak = team.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                             .NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                    goalsFor = team.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                               .NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                    goalsAgainst = team.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                   .NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                   .NextSibling.NextSibling.InnerText;
                    cleanSheets = team.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                  .NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                  .NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                    lastTenGames = team.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                   .NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                   .NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                    homeRecord = team.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                 .NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                 .NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                 .InnerText;
                    awayRecord = team.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                 .NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                 .NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                 .NextSibling.NextSibling.InnerText;
                    oneGoalGames = team.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                   .NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                   .NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling.NextSibling
                                   .NextSibling.NextSibling.NextSibling.NextSibling.InnerText;
                    teamIconUrl = team
                                  .SelectSingleNode(
                        $"//*[@id='content']/div/div/div/div/div/div/div[1]/table/tbody[{teamIndex}]/tr/td[1]/div/img")
                                  .Attributes["src"].Value;
                    teamUrl = team
                              .SelectSingleNode(
                        $"//*[@id='content']/div/div/div/div/div/div/div[1]/table/tbody[{teamIndex}]/tr/td[1]/div/a")
                              .Attributes["href"].Value;

                    // Console.Write($"TeamName: {teamName}\nTeamIcon: {teamIconUrl}\nTeamUrl: {teamUrl}\n\n");
                    var iconEnlarge = teamIconUrl.Replace("p38", "p100");
                    teamIconUrl = string.Join(String.Empty, "https://www.leaguegaming.com" + iconEnlarge);
                    teamUrl     = string.Join(string.Empty, "https://www.leaguegaming.com/forums/" + teamUrl);
                    var parameters = HttpUtility.ParseQueryString(new Uri(teamUrl).Query);
                    teamID = parameters.Get("teamid");
                    var tempStrip = rank.Replace(")", "").Trim();
                    rank = tempStrip;

                    if (SeasonTypeId == "pre")
                    {
                        SeasonTypeId = "pre-season";
                    }
                    else if (SeasonTypeId == "reg")
                    {
                        SeasonTypeId = "regular";
                    }

                    DataSaver.SaveTeam(int.Parse(teamID), int.Parse(rank), teamName, gamesPlayed, gamesWon,
                                       gamesDrawn, gamesLost, points, streak, goalsFor, goalsAgainst, cleanSheets, lastTenGames,
                                       homeRecord, awayRecord, oneGoalGames, teamIconUrl, teamUrl, System, SeasonId,
                                       SeasonTypeId, Command);
                    teamIndex++;
                    GC.Collect();
                }
                Log.Logger.Warning("Team Databases updated.");
                return(true);
            }
            catch (Exception ex)
            {
                Log.Logger.Error($"Error with TeamStatsHandler: {ex}");
                GC.Collect();
                return(false);
            }
        }