public static bool GetGoalie(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 psnDoc = web.Load(Fetch.GetURL(League, Trigger, HistoricalSeasonID, SeasonTypeId)); #region Player total calculator var countPlayers = psnDoc.DocumentNode.SelectNodes(("//*[@id='lgtable_goaliestats51']/tbody/tr")); if (countPlayers == null) { return(false); } var playerTotal = countPlayers.Count; #endregion try { for (int i = 1; i <= playerTotal; i++) { var findPlayerNodes = psnDoc.DocumentNode.SelectNodes($"//*[@id='lgtable_goaliestats51']/tbody/tr[1]"); if (findPlayerNodes == null) { break; } foreach (var player in findPlayerNodes) { #region parse variables var position = ""; var lgRank = ""; var teamIconShort = ""; var playerName = ""; var gamesPlayed = ""; var record = ""; var goalsAgainst = ""; var shotsAgainst = ""; var saves = ""; var savePercentage = ""; var goalsAgainstAvg = ""; var cleanSheets = ""; var manOfTheMatch = ""; var avgMatchRating = ""; var playerShortURL = ""; #endregion position = WebUtility.HtmlDecode(player .SelectSingleNode($"//*[@id='lgtable_memberstats51']/tbody/tr[{i}]/td[2]/span").InnerText); teamIconShort = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_goaliestats51']/tbody/tr[{i}]/td[2]/img").Attributes["src"].Value); playerName = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_goaliestats51']/tbody/tr[{i}]/td[2]/a").InnerText); gamesPlayed = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_goaliestats51']/tbody/tr[{i}]/td[4]").InnerText); record = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_goaliestats51']/tbody/tr[{i}]/td[5]").InnerText); goalsAgainst = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_goaliestats51']/tbody/tr[{i}]/td[6]").InnerText); shotsAgainst = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_goaliestats51']/tbody/tr[{i}]/td[7]").InnerText); saves = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_goaliestats51']/tbody/tr[{i}]/td[8]").InnerText); savePercentage = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_goaliestats51']/tbody/tr[{i}]/td[9]").InnerText); goalsAgainstAvg = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_goaliestats51']/tbody/tr[{i}]/td[10]").InnerText); cleanSheets = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_goaliestats51']/tbody/tr[{i}]/td[11]").InnerText); manOfTheMatch = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_goaliestats51']/tbody/tr[{i}]/td[12]").InnerText); avgMatchRating = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_goaliestats51']/tbody/tr[{i}]/td[13]").InnerText); playerShortURL = WebUtility.HtmlDecode(player.SelectSingleNode($"//*[@id='lgtable_goaliestats51']/tbody/tr[{i}]/td[2]/a").Attributes["href"].Value); var playerURL = string.Join(string.Empty, "https://www.leaguegaming.com/forums/" + playerShortURL); var temp = HttpUtility.ParseQueryString(new Uri(playerURL).Query); var playerID = int.Parse(temp.Get("userid")); var iconEnlarge = teamIconShort.Replace("p16", "p100"); var iconURL = string.Join(string.Empty, "https://www.leaguegaming.com" + iconEnlarge); if (SeasonTypeId == "pre") { SeasonTypeId = "pre-season"; } else if (SeasonTypeId == "reg") { SeasonTypeId = "regular"; } if (savePercentage == String.Empty) { savePercentage = "0"; } Tools.DataSaver.SavePlayerUrl(playerID, playerName, playerURL); //Console.WriteLine($"Saved {playerName} url. GoaliEngine"); CareerEngine.GetCareer(playerID, playerName, League); //Console.WriteLine($"{playerName}, career saved. GoalieEngine"); DataSaver.SaveGoalie(playerID, League, playerName, gamesPlayed, record, goalsAgainst, shotsAgainst, saves, savePercentage, goalsAgainstAvg, cleanSheets, manOfTheMatch, avgMatchRating, playerURL, iconURL, Command, HistoricalSeasonID, SeasonTypeId); GC.Collect(); } } return(true); } catch (Exception e) { Log.Logger.Error(e, $"Error processing PSN Goalie Stats {currentMethod}"); return(false); } }
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); } }