private Deck GetDeck(string jsonDeck)
        {
            Deck toReturn = new Deck();

            string[][] res = jsonDeck.Trim('[').Trim(']').Split(new[] { "],[" }, StringSplitOptions.RemoveEmptyEntries).Select(p => p.Split(',')).ToArray();

            HtmlWeb web = new HtmlWeb();

            foreach (string[] strings in res)
            {
                string cardName;
                if (cardMaper.ContainsKey(strings[0]))
                {
                    cardName = cardMaper[strings[0]];
                }
                else
                {
                    HtmlDocument doc = web.Load(URL + CARD_END_POINT + strings[0]);
                    cardName = doc.DocumentNode.SelectSingleNode("//title").InnerText;
                    cardName = WebUtility.HtmlDecode(cardName.Split(new[] { " - HSReplay.net" }, StringSplitOptions.RemoveEmptyEntries)[0]);
                    cardMaper.Add(strings[0], cardName);
                }

                Card card = MyCollection.Get(cardName);
                toReturn.Cards.Add(card, int.Parse(strings[1]));
            }

            return(toReturn);
        }
        private Deck GetDeck(string url)
        {
            Deck         toReturn = new Deck();
            HtmlWeb      web      = new HtmlWeb();
            HtmlDocument doc      = web.Load(url);

            toReturn.Url = url;
            if (doc.DocumentNode.SelectNodes("//*[contains(@class,'article-content')]") == null)
            {
                return(null);
            }

            toReturn.UpdateDateString = doc.DocumentNode.SelectSingleNode("//*[contains(@itemprop,'datePublished')]").GetAttributeValue("content", "");

            foreach (HtmlNode cardSection in doc.DocumentNode.SelectNodes("//*[contains(@class,'article-content')]/section"))
            {
                HtmlNode table = cardSection.SelectSingleNode("table");
                if (table == null)
                {
                    continue;
                }

                toReturn.Class = table.SelectSingleNode("thead/tr/th[1]").InnerText;

                foreach (HtmlNode cardNode in table.SelectNodes("tbody/tr/td"))
                {
                    string cardName = cardNode.InnerText;
                    if (cardName == "")
                    {
                        continue;
                    }
                    cardName = cardName.Substring(3).Trim();

                    int cardCount;
                    if (cardNode.InnerText.Contains("2 x"))
                    {
                        cardCount = 2;
                    }
                    else if (cardNode.InnerText.Contains("1 x"))
                    {
                        cardCount = 1;
                    }
                    else
                    {
                        continue;
                    }

                    Card card = MyCollection.Get(cardName);
                    if (card == null)
                    {
                        continue;
                    }
                    toReturn.Cards.Add(card, cardCount);
                }

                break;
            }

            return(toReturn);
        }
Exemple #3
0
        private Deck GetDeck(string url)
        {
            Deck toReturn = new Deck();

            HtmlWeb      web = new HtmlWeb();
            HtmlDocument doc = web.Load(BASE_URL + url);

            HtmlNode deckLink = doc.DocumentNode.SelectSingleNode("//*[contains(@class,'dt-col-decklist-name')]/a");

            if (deckLink == null)
            {
                return(null);
            }
            string deckUrl = deckLink.GetAttributeValue("href", string.Empty);

            doc          = web.Load(BASE_URL + deckUrl);
            toReturn.Url = BASE_URL + url;
            HtmlNodeCollection nodes = doc.DocumentNode.SelectNodes("//*[contains(@class,'dt-decklist-metadata')]/dt");

            toReturn.Class            = nodes[1].SelectSingleNode("a").InnerText;
            toReturn.Name             = WebUtility.HtmlDecode(nodes[2].SelectSingleNode("a").InnerText);
            toReturn.UpdateDateString = nodes[nodes.Count - 1].InnerText;

            foreach (HtmlNode cardLink in doc.DocumentNode.SelectNodes("//*[contains(@class,'dt-cardlist')]/li"))
            {
                string cardName  = WebUtility.HtmlDecode(cardLink.SelectSingleNode("*[contains(@class,'dt-card-name')]").InnerText).Trim();
                string cardCount = cardLink.SelectSingleNode("*[contains(@class,'dt-card-quantity')]").InnerText;

                Card card = MyCollection.Get(cardName);
                toReturn.Cards.Add(card, int.Parse(cardCount));
            }

            return(toReturn);
        }
        private Deck GetDeck(string url)
        {
            Deck        toReturn = new Deck();
            RestClient  client   = new RestClient(URL);
            RestRequest request  = new RestRequest(END_POINT_DECK, Method.GET);

            request.AddUrlSegment("slug", url);

            IRestResponse response = client.Execute(request);
            dynamic       deck     = Json.Decode(response.Content);

            toReturn.UpdateDateString = deck.createdDate;
            toReturn.Url = DECK_URL + url;

            foreach (dynamic cardObj in deck.cards)
            {
                Card card = MyCollection.Get(cardObj.card.name);
                toReturn.Cards.Add(card, cardObj.cardQuantity);
            }

            return(toReturn);
        }
        private Deck GetDeck(string url)
        {
            Deck toReturn = new Deck();

            HtmlWeb      web = new HtmlWeb();
            HtmlDocument doc = web.Load(url);

            toReturn.Url = url;
            //toReturn.Tier = 5;
            //IEnumerable<HtmlNode> scripts = doc.DocumentNode.Descendants("script");

            //foreach (var scriptNode in scripts)
            //{
            //    string script = scriptNode.InnerHtml;
            //    if (script == "") continue;
            //    try
            //    {
            //        string winRateString = script.Split(new[] { "data: [" }, StringSplitOptions.None)[1].Split(new[] { ", ]" }, StringSplitOptions.None)[0];
            //        string[] winRateArray = winRateString.Split(',');

            //        double total = winRateArray.Aggregate(0.0, (current, winRate) => current + int.Parse(winRate));

            //        double deckWinPercent = total / (winRateArray.Length * 100);

            //        if (deckWinPercent >= 0.55)
            //        {
            //            toReturn.Tier = 1;
            //        }
            //        else if (deckWinPercent >= 0.50)
            //        {
            //            toReturn.Tier = 2;
            //        }
            //        else if (deckWinPercent >= 0.45)
            //        {
            //            toReturn.Tier = 3;
            //        }
            //        else if (deckWinPercent >= 0.40)
            //        {
            //            toReturn.Tier = 4;
            //        }
            //        else
            //        {
            //            toReturn.Tier = 5;
            //        }

            //    }
            //    catch(Exception)
            //    {
            //        // ignored
            //    }
            //}

            toReturn.Class            = doc.DocumentNode.SelectNodes("//*[contains(@class,'deck-info')]/a")[0].InnerText;
            toReturn.UpdateDateString = doc.DocumentNode.SelectSingleNode("//*[contains(@class,'updated')]").GetAttributeValue("datetime", DateTime.Now.ToString());

            foreach (HtmlNode cardLink in doc.DocumentNode.SelectNodes("//*[contains(@class,'card-frame')]"))
            {
                string cardName  = WebUtility.HtmlDecode(cardLink.SelectSingleNode("a/*[contains(@class,'card-name')]").InnerText).Replace('’', '\'');
                string cardCount = cardLink.SelectSingleNode("*[contains(@class,'card-count')]").InnerText;

                Card card = MyCollection.Get(cardName);
                toReturn.Cards.Add(card, int.Parse(cardCount));
            }

            return(toReturn);
        }