Last active
August 29, 2015 14:01
-
-
Save AlexArchive/39ec1d22d3fe6965db35 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static readonly HttpClient _client = new HttpClient(); | |
| private async static void ObtainProfileData(string gamertag, string region) | |
| { | |
| var response = await _client.GetAsync("http://live.xbox.com/" + region + "/Profile?gamertag=" + gamertag); | |
| if (!response.IsSuccessStatusCode) | |
| { | |
| Console.WriteLine("{0} Gamertag not found.", response.StatusCode); | |
| return; | |
| } | |
| var pageData = await response.Content.ReadAsStringAsync(); | |
| var document = new HtmlDocument(); | |
| document.LoadHtml(pageData); | |
| var gamerscore = document.DocumentNode.SelectNodes("//div[@class='gamerscore']").Single().InnerText; | |
| Console.WriteLine("Gamerscore: {0}", gamerscore); | |
| var temp = document.DocumentNode.SelectNodes("//div[@class='goldBadge']"); | |
| var tier = temp == null ? "Silver" : "Gold"; | |
| Console.WriteLine("Tier: {0}", tier); | |
| var starValues = new Dictionary<string, int> { | |
| {"Empty", 0}, | |
| {"Quater", 25}, | |
| {"Half", 50}, | |
| {"ThreeQuater", 75}, | |
| {"Full", 100} | |
| }; | |
| var stars = document.DocumentNode.SelectNodes("//div[starts-with(@class,'Star')]"); | |
| int reputation = | |
| stars.Select(star => star.Attributes["class"].Value.Split(new[] {' '})[1]) | |
| .Select(kind => starValues[kind]) | |
| .Sum(); | |
| Console.WriteLine("Reputation: {0}", reputation); | |
| var presence = document.DocumentNode.SelectNodes("//div[@class='presence']").Single().InnerText; | |
| Console.WriteLine("Presence: {0}", presence); | |
| var online = presence.StartsWith("Online") && presence != "Online Status Unavailable"; | |
| Console.WriteLine("Online: {0}", online); | |
| var motto = "None"; | |
| temp = document.DocumentNode.SelectNodes("//div[@class='motto']"); | |
| if (temp != null) | |
| motto = temp.Single().InnerText; | |
| Console.WriteLine("Motto: {0}", motto.TrimStart().TrimEnd()); | |
| var name = document.DocumentNode.SelectNodes("//div[@class='name']/div").Single().InnerText; | |
| Console.WriteLine("Name: {0}", name); | |
| var location = document.DocumentNode.SelectNodes("//div[@class='location']/div").Single().InnerText; | |
| Console.WriteLine("Location: {0}", location); | |
| var bio = document.DocumentNode.SelectNodes("//div[@class='bio']/div").Single().InnerText; | |
| Console.WriteLine("Bio: {0}", bio); | |
| var name = document.DocumentNode.SelectNodes("//div[@class='name']/div").Single().InnerText; | |
| Console.WriteLine("Name: {0}", name); | |
| var location = document.DocumentNode.SelectNodes("//div[@class='location']/div").Single().InnerText; | |
| Console.WriteLine("Location: {0}", location); | |
| var bio = document.DocumentNode.SelectNodes("//div[@class='bio']/div").Single().InnerText; | |
| Console.WriteLine("Bio: {0}", bio); | |
| var imageFull = "http://avatar.xboxlive.com/avatar/" + gamertag + "/avatar-body.png"; | |
| Console.WriteLine("Image Full: {0}", imageFull); | |
| var imageSmall = "http://avatar.xboxlive.com/avatar/" + gamertag + "/avatarpic-s.png"; | |
| Console.WriteLine("Image Small: {0}", imageSmall); | |
| var imageLarge = "http://avatar.xboxlive.com/avatar/" + gamertag + "/avatarpic-l.png"; | |
| Console.WriteLine("Image Large: {0}", imageLarge); | |
| var tileTemp = document.DocumentNode.SelectSingleNode("//img[@class='gamerpic']"); | |
| var tile = tileTemp.GetAttributeValue("src", null); | |
| tile = tile != null ? tile.Replace("https://avatar-ssl", "http://avatar") : "Unavailable."; | |
| Console.WriteLine(string.Format("Tile: {0}", tile)); | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static readonly HttpClient _client = new HttpClient(); | |
| private static readonly Dictionary<string, int> _starValues | |
| = new Dictionary<string, int> | |
| { | |
| {"Star Empty", 0}, | |
| {"Star Quater", 25}, | |
| {"Star Half", 50}, | |
| {"Star ThreeQuater", 75}, | |
| {"Star Full", 100} | |
| }; | |
| private async static void ObtainProfileData(string gamertag, string region) | |
| { | |
| var response = await _client.GetAsync("http://live.xbox.com/" + region + "/Profile?gamertag=" + gamertag); | |
| if (!response.IsSuccessStatusCode) | |
| return; | |
| var pageData = await response.Content.ReadAsStringAsync(); | |
| var document = new HtmlDocument(); | |
| document.LoadHtml(pageData); | |
| var documentNode = document.DocumentNode; | |
| var profile = new Profile { Gamertag = gamertag }; | |
| profile.Gamerscore = documentNode.SelectSingleNode("//div[@class='gamerscore']").InnerText; | |
| var badgeNode = documentNode.SelectSingleNode("//div[@class='goldBadge']"); | |
| profile.Tier = badgeNode == null ? "Silver" : "Gold"; | |
| var starNodes = documentNode.SelectNodes("//div[starts-with(@class, 'Star')]"); | |
| foreach (var star in starNodes) | |
| { | |
| var kind = star.GetAttributeValue("class", null); | |
| profile.Reputation += _starValues[kind]; | |
| } | |
| profile.Presence = documentNode.SelectSingleNode("//div[@class='presence']").InnerText; | |
| profile.Online = profile.Presence.StartsWith("Online") && profile.Presence != "Online Status Unavailable"; | |
| var mottoTemp = documentNode.SelectSingleNode("//div[@class='motto']"); | |
| profile.Motto = mottoTemp == null ? "None" : mottoTemp.InnerText.Trim(); | |
| profile.Name = documentNode.SelectSingleNode("//div[@class='name']/div").InnerText; | |
| profile.Location = documentNode.SelectSingleNode("//div[@class='location']/div").InnerText; | |
| profile.Biography = documentNode.SelectSingleNode("//div[@class='bio']/div").InnerText.Trim(); | |
| profile.Avatar = new Avatar(); | |
| profile.Avatar.Full = string.Format("http://avatar.xboxlive.com/avatar/{0}/avatar-body.png", gamertag); | |
| profile.Avatar.Small = string.Format("http://avatar.xboxlive.com/avatar/{0}/avatarpic-s.png", gamertag); | |
| profile.Avatar.Large = string.Format("http://avatar.xboxlive.com/avatar/{0}/avatarpic-l.png", gamertag); | |
| var tileTemp = documentNode.SelectSingleNode("//img[@class='gamerpic']").GetAttributeValue("src", null); | |
| profile.Avatar.Tile = tileTemp != null ? tileTemp.Replace("https://avatar-ssl", "http://avatar") : "Unavailable."; | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| private static readonly HttpClient _client = new HttpClient(); | |
| private static readonly Dictionary<string, int> _starValues | |
| = new Dictionary<string, int> | |
| { | |
| {"Star Empty", 0}, | |
| {"Star Quarter", 25}, | |
| {"Star Half", 50}, | |
| {"Star ThreeQuarter", 75}, | |
| {"Star Full", 100} | |
| }; | |
| private async static void ObtainProfileData(string gamertag, string region) | |
| { | |
| var response = await _client.GetAsync("http://live.xbox.com/" + region + "/Profile?gamertag=" + gamertag); | |
| if (!response.IsSuccessStatusCode) | |
| Console.WriteLine("{0} Gamertag not found.", response.StatusCode); | |
| var pageData = await response.Content.ReadAsStringAsync(); | |
| var document = new HtmlDocument(); | |
| document.LoadHtml(pageData); | |
| var documentNode = document.DocumentNode; | |
| var profile = new Profile { Gamertag = gamertag }; | |
| profile.Gamerscore = documentNode.SelectSingleNode("//div[@class='gamerscore']").InnerText; | |
| var badgeNode = documentNode.SelectSingleNode("//div[@class='goldBadge']"); | |
| profile.Tier = badgeNode == null ? "Silver" : "Gold"; | |
| var starNodes = documentNode.SelectNodes("//div[starts-with(@class, 'Star')]"); | |
| foreach (var star in starNodes) | |
| { | |
| var kind = star.GetAttributeValue("class", null); | |
| profile.Reputation += starValues[kind]; | |
| } | |
| profile.Presence = documentNode.SelectSingleNode("//div[@class='presence']").InnerText; | |
| profile.Online = profile.Presence.StartsWith("Online") && profile.Presence != "Online Status Unavailable"; | |
| var mottoNode = documentNode.SelectSingleNode("//div[@class='motto']"); | |
| profile.Motto = mottoNode != null ? mottoNode.InnerText.Trim() : "None"; | |
| profile.Name = documentNode.SelectSingleNode("//div[@class='name']/div").InnerText; | |
| profile.Location = documentNode.SelectSingleNode("//div[@class='location']/div").InnerText; | |
| profile.Biography = documentNode.SelectSingleNode("//div[@class='bio']/div").InnerText.Trim(); | |
| profile.Avatar = new Avatar(); | |
| profile.Avatar.Full = string.Format("http://avatar.xboxlive.com/avatar/{0}/avatar-body.png", gamertag); | |
| profile.Avatar.Small = string.Format("http://avatar.xboxlive.com/avatar/{0}/avatarpic-s.png", gamertag); | |
| profile.Avatar.Large = string.Format("http://avatar.xboxlive.com/avatar/{0}/avatarpic-l.png", gamertag); | |
| profile.Avatar.Tile = documentNode.SelectSingleNode("//img[@class='gamerpic']").GetAttributeValue("src", null); | |
| profile.Avatar.Tile = profile.Avatar.Tile.Replace("https://avatar-ssl", "http://avatar"); | |
| } | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment