예제 #1
0
        /// <summary>
        /// a method to create the union of 2 lists
        /// </summary>
        /// <param name="masterList">A master card list</param>
        /// <param name="mergeList">the list to merge into the master list</param>
        public List<Card> buildMyMaster(List<Card> listA, List<Card> listB)
        {
            List<Card> output = new List<Card>();
            bool cardAdded;

            foreach (Card a in listA)
            {
                Card cCard = new Card();
                cardAdded = false;

                for (int i = 0; i < listB.Count; i++)
                {
                    if (a.NamePlain.Equals(listB[i].NamePlain))
                    {
                        cardAdded = true;

                        cCard.Name = a.Name != null ? a.Name : listB[i].Name;
                        cCard.NamePlain = listB[i].NamePlain != null ? listB[i].NamePlain : a.NamePlain;
                        cCard.Rarity = listB[i].Rarity != null ? listB[i].Rarity : a.Rarity;
                        cCard.Set = listB[i].Set != null ? listB[i].Set : a.Set;
                        cCard.PriceAction = listB[i].PriceAction != null ? listB[i].PriceAction : a.PriceAction;
                        cCard.BuyPriceRegular = listB[i].BuyPriceRegular != 0 ? listB[i].BuyPriceRegular : a.BuyPriceRegular;
                        cCard.SellPriceRegular = listB[i].SellPriceRegular != 0 ? listB[i].SellPriceRegular : a.SellPriceRegular;
                        cCard.BuyPriceFoil = listB[i].BuyPriceFoil != 0 ? listB[i].BuyPriceFoil : a.BuyPriceFoil;
                        cCard.SellPriceFoil = listB[i].SellPriceFoil != 0 ? listB[i].SellPriceFoil : a.SellPriceFoil;
                        cCard.BuyQtyRegular = listB[i].BuyQtyRegular != 0 ? listB[i].BuyQtyRegular : a.BuyQtyRegular;
                        cCard.BuyQtyFoil = listB[i].BuyQtyFoil != 0 ? listB[i].BuyQtyFoil : a.BuyQtyFoil;

                        output.Add(cCard);
                        continue;
                    }
                }

                if (!cardAdded) output.Add(a);
            }

            return output;
        }
예제 #2
0
        /// <summary>
        /// Method to get, parse and return MTGGOldfish website prices.
        /// </summary>
        /// <param name="website">The web address of the MTGGoldfish page you would like to parse</param>
        /// <param name="ROOTDIRECTORY">The Directory where the source will be downloaded to.</param>
        /// <returns>A List of Cards</returns>
        public List<Card> SaPTCGpaper(string website, string setAbbrv, string ROOTDIRECTORY)
        {
            Console.Write("Scraping " + website.ToString() + "...\n");

            string filePath = ROOTDIRECTORY + @"/" + "LastScrapedSite-Data.txt";
            bool startParse = false;
            string webData = getSource(website);
            char[] delimiterChars = { '<', '>' };
            System.IO.StreamWriter file = new System.IO.StreamWriter(filePath);
            file.WriteLine(webData);
            file.Close();
            var cardList = new List<Card>();
            Card c = new Card();

            Console.Write("Parsing " + website.ToString() + " scrape...\n");

            foreach (string line in File.ReadAllLines(filePath))
            {
                if (line.Contains("TR height=20"))
                {
                    startParse = true;
                }

                //If startParse is not TRUE or the line is empty, carry on
                if (!startParse || string.IsNullOrEmpty(line)) continue;

                String[] lineChunks = Regex.Split(line, "TR height=20");
                foreach (string chunk in lineChunks)
                {
                    string[] ChunkBits = chunk.Split(delimiterChars);
                    foreach (string bit in ChunkBits)
                    {
                        if (ChunkBits.Length > 13)
                        {
                            decimal buyHigh;
                            decimal buyMid;
                            decimal buyLow;
                            c.Set = setAbbrv;
                            c.Name = ChunkBits[5].Substring(6).Replace(" // ", "/");
                            c.NamePlain = c.Name.Replace("'", "").Replace(",", "").ToLower() + "(" + c.Set.ToLower() + ")";
                            c.Rarity = ChunkBits[37].Substring(6);
                            decimal.TryParse((ChunkBits[45].Replace("&nbsp;", "")).Substring(1), out buyHigh);
                            c.PaperHIGH = buyHigh;
                            decimal.TryParse((ChunkBits[53].Replace("&nbsp;", "")).Substring(1), out buyMid);
                            c.PaperMID = buyMid;
                            decimal.TryParse((ChunkBits[61].Replace("&nbsp;", "")).Substring(1), out buyLow);
                            c.PaperLOW = buyLow;
                            if (!c.NamePlain.Equals(""))
                            {
                                cardList.Add(c);
                                c = new Card();
                                break;
                            }
                        }
                    }

                }
            }

            orderCardList(cardList);
            MasterOutput = buildMyMaster(MasterOutput, cardList);
            return cardList;
        }
예제 #3
0
        /// <summary>
        /// Method to parse the CardsMTGO3.txt file
        /// </summary>
        /// <param name="fileLocation">The directory where CardsMTGO3.txt is located</param>
        /// <returns>A List of Cards</returns>
        public List<Card> makeCardsMTGO3List(string fileLocation)
        {
            Console.Write("*** CardsMTGO3 ***\n");
            Console.Write("\t...parsing CardsMTGO3.txt file\n");
            List<Card> cardList = new List<Card>();
            string filePath = fileLocation + @"/" + "CardsMTGO3.txt";
            string[] coreSets = { "2010", "2011", "2012", "2013", "2014" };

            foreach (string line in File.ReadAllLines(filePath))
            {
                Card c = new Card();
                String[] lineChunks = line.Split();
                c.Set = lineChunks[5];
                c.Rarity = lineChunks[6];
                bool nameNext = false;
                bool nameDone = false;
                bool booster = false;
                bool coresetTest = false;

                if (c.Rarity.Equals("U") || c.Rarity.Equals("C")) continue;

                if (line.Contains("Magic"))
                {
                    coresetTest = true;
                }
                else
                {
                    coresetTest = false;
                }

                foreach (string chunk in lineChunks)
                {
                    if (!nameDone)
                    {
                        decimal crap;

                        if (c.Name == null && decimal.TryParse(chunk, out crap)) continue;

                        if (nameDone && booster && coreSets.Contains(chunk.ToString())) continue;

                        if (c.Name != null && decimal.TryParse(chunk, out crap))
                        {
                            if (coresetTest && (chunk.Equals("2010") ||
                                chunk.Equals("2011") || chunk.Equals("2012") ||
                                chunk.Equals("2013") || chunk.Equals("2014")))
                            {
                                for (int i = Array.IndexOf(lineChunks, "Magic") + 1; i < lineChunks.Length; i++)
                                {
                                    c.Name += " " + lineChunks[i].ToString();
                                    //hit the end of the file name, break out of loop
                                    if (c.Name.Contains("#"))
                                    {
                                        break;
                                    }
                                }
                                booster = true;
                            }
                            else
                            {
                                booster = false;
                            }

                            c.Name = c.Name.Replace("#", "");
                            c.NamePlain = c.Name.Replace("'", "").Replace(",", "").ToLower() + "(" + c.Set.ToLower() + ")";
                            nameDone = true;
                            booster = false;
                            if (!coreSets.Contains(chunk.ToString())) c.SellPriceRegular = decimal.Round(crap, 3);
                            continue;
                        }

                        if (c.Set.Equals(chunk)) continue;
                        if (c.Rarity.Equals(chunk))
                        {
                            nameNext = true;
                            continue;
                        }

                        if (nameNext)
                        {
                            if (c.Name == null)
                            {
                                c.Name = chunk;
                                continue;
                            }
                            else
                            {
                                c.Name = c.Name + " " + chunk;
                                continue;
                            }
                        }
                    }
                    if (nameDone && !coreSets.Contains(chunk.ToString()))
                    {
                        decimal aPrice;
                        decimal.TryParse(chunk, out aPrice);

                        //the name is done, now parse the values
                        if (c.SellPriceRegular == 0)
                        {
                            c.SellPriceRegular = decimal.Round(aPrice, 3);
                            continue;
                        }
                        else if (c.SellPriceFoil == 0)
                        {
                            c.SellPriceFoil = decimal.Round(aPrice, 3);
                            continue;
                        }
                        else if (c.BuyPriceRegular == 0)
                        {
                            c.BuyPriceRegular = decimal.Round(aPrice, 3);
                            continue;
                        }
                        else if (c.BuyPriceFoil == 0)
                        {
                            c.BuyPriceFoil = decimal.Round(aPrice, 3);
                            continue;
                        }
                    }
                }
                cardList.Add(c);
            }
            Console.Write("\t...ordering and returing list\n");
            cardList = cardList.OrderBy(x => x.Set).ThenBy(x => x.Name).ToList();
            Console.WriteLine("\t...creating one list to rule them all!!!");
            MasterOutput = cardList;

            return cardList;
        }