public static string SmallRaceImage(Character character) { if (!string.IsNullOrEmpty(character.Race)) { return string.Format("http://static.wowhead.com/images/wow/icons/small/race_{0}_male.jpg", character.Race.ToLowerInvariant().Replace(" ", "")); } return ""; }
public Character Parse(Character character, bool force) { stopwatch.Reset(); Stopwatch watch = new Stopwatch(); watch.Start(); _current = character; // Only parse the character once a day unless forced if (character.LastParseDate.HasValue && character.LastParseDate.Value.AddDays(7) > DateTime.Now && !force) { return character; } ParseCharacterInformation(character); //character.Achievements.Clear(); string mainAchievementPageUrl = string.Format("http://{2}.battle.net/wow/en/character/{0}/{1}/achievement", character.Server, character.Name, character.Region); HtmlDocument doc = DownloadPage(mainAchievementPageUrl); List<AchievedAchievement> achievements = new List<AchievedAchievement>(); ProcessPageForAchievements(doc.DocumentNode, character); pagesToParse = new List<HtmlDocument>(); IList<string> extraPages = FindSubAchievementPages(doc.DocumentNode); SmartThreadPool pool = new SmartThreadPool(); foreach (string pageUrl in extraPages) { pool.QueueWorkItem(new WorkItemCallback(ProcessPageOnNewThread), pageUrl); } pool.Start(); pool.WaitForIdle(); try { foreach (HtmlDocument page in pagesToParse) { ProcessPageForAchievements(page.DocumentNode, character); } } catch (IndexOutOfRangeException) { } character.LastParseDate = DateTime.Now; character.CurrentPoints = character.TotalAchievementPoints; watch.Stop(); return character; }
public IList<AchievedAchievement> Parse(HtmlNode achievementNode, Character character) { List<Achievement> achievements = new List<Achievement>(); List<AchievedAchievement> actualAchievements = new List<AchievedAchievement>(); if (achievementNode == null) { throw new ArgumentNullException("achievementNode"); } string achievementId = achievementNode.Attributes["data-id"].Value; int blizzardId = 0; int.TryParse(achievementId, out blizzardId); Achievement achievement = _service.Find(blizzardId); if (achievement == null) { Console.WriteLine("Found unknown achievement {0}", achievementId); } if (!achievementNode.Attributes["class"].Value.Contains("locked")) { // DateTime whenAchieved = GetValueAsDateTime(achievementNode, "./div[@class='points-big border-8']/span[@class='date']"); if (!character.HasAchieved(achievement)) { character.AddNewAchivement(whenAchieved, achievement); } // check to see if achievement is part of a series if (achievement != null && achievement.Series != null) { // get all achievements under the one we have displayed foreach (Achievement seriesAchievement in _service.GetAllInSeries(achievement.Series).Where(a => a.SeriesOrder < achievement.SeriesOrder)) { if (!character.HasAchieved(achievement)) { character.AddNewAchivement(whenAchieved.AddDays(-1), seriesAchievement); } } } } return actualAchievements; }
private void ProcessPageForAchievements(HtmlNode page, Character character) { HtmlNode achievementList = page.SelectSingleNode("//div[@class='container']"); if (achievementList != null) { ProcessAchievementList(achievementList, character); } }
private void ProcessAchievementList(HtmlNode achievementList, Character character) { HtmlNodeCollection achievementNodes = achievementList.SelectNodes("//li"); if (achievementNodes != null) { foreach (HtmlNode individualAchievement in achievementNodes) { if (IsAchievementContainer(individualAchievement)) { _achievementParser.Parse(individualAchievement, character); } } } }
void ParseCharacterInformation(Character character) { string mainPageUrl = string.Format("http://{2}.battle.net/wow/en/character/{0}/{1}/simple", character.Server, character.Name, character.Region); HtmlDocument doc = DownloadPage(mainPageUrl); character.Guild = GetValueAsString(doc.DocumentNode, "//div[@class='guild']"); character.Level = GetValueAsInt32(doc.DocumentNode, "//span[@class='level']/strong"); character.Class = GetValueAsString(doc.DocumentNode, "//a[@class='class']"); character.Race = GetValueAsString(doc.DocumentNode, "//a[@class='race']"); HtmlNode sideNode = doc.DocumentNode.SelectSingleNode("//div[@id='profile-wrapper']"); if (sideNode != null) { if (sideNode.Attributes["class"].Value.Contains("horde")) { character.Side = 1; } else { character.Side = 2; } } //guild }