Exemplo n.º 1
0
        private static async Task AddProductLoop()
        {
            System.Console.WriteLine("Add product url (Newegg.com, BHPhotoVideo.com Supported):");
            String url = System.Console.ReadLine().Trim();

            if (url.Contains("http") && (url.Contains("newegg.com") || url.Contains("bhphotovideo.com") || url.Contains("tigerdirect.com") || url.Contains("sabrepc.com")))
            {
                Product product;

                if (url.Contains("newegg.com"))
                {
                    NewEggParser parser = new NewEggParser();
                    product = await parser.RequestProduct(url);
                }
                else if (url.Contains("bhphotovideo.com"))
                {
                    BHParser parser = new BHParser();
                    product = await parser.RequestProduct(url);
                }
                else if (url.Contains("tigerdirect.com"))
                {
                    TigerDirectParser parser = new TigerDirectParser();
                    product = await parser.RequestProduct(url);
                }
                else
                {
                    SabreParser parser = new SabreParser();
                    product = await parser.RequestProduct(url);
                }

                OutputProduct(product);

                bool productExists = scrapperData.ProductsToCheck.Where(x => x.Url.Equals(url, StringComparison.InvariantCultureIgnoreCase)).Any();

                if (productExists)
                {
                    Console.WriteLine("This product is already being monitored and can't be added to the list.");
                }
                else
                {
                    System.Console.WriteLine("Do you want to monitor this product? [Y/N]: ");
                    string answ = System.Console.ReadLine().ToLower();
                    if (answ.Equals("y"))
                    {
                        scrapperData.ProductsToCheck.Add(product);
                        SortProductsByStoreName();
                        System.Console.WriteLine("Now monitoring " + product.Name + "\n");
                        ConfigurationToJSON(scrapperData, jsonFile);
                        await RunParsers(true);
                    }
                }
            }
        }
Exemplo n.º 2
0
        private static async Task RunParsers(bool ForceConsolePrint = false)
        {
            foreach (Product origproduct in scrapperData.ProductsToCheck)
            //Parallel.ForEach(scrapperData.ProductsToCheck, async (origproduct) =>
            {
                Product product;

                if (origproduct.Url.Contains("newegg.com"))
                {
                    NewEggParser parser = new NewEggParser();
                    product = await parser.RequestProduct(origproduct.Url);
                }
                else if (origproduct.Url.Contains("tigerdirect.com"))
                {
                    TigerDirectParser parser = new TigerDirectParser();
                    product = await parser.RequestProduct(origproduct.Url);
                }
                else if (origproduct.Url.Contains("bhphotovideo.com"))
                {
                    BHParser parser = new BHParser();
                    product = await parser.RequestProduct(origproduct.Url);
                }
                else
                {
                    SabreParser parser = new SabreParser();
                    product = await parser.RequestProduct(origproduct.Url);
                }

                if ((inMainMenu || ForceConsolePrint) && product.Valid)
                {
                    OutputProduct(product);
                }
                if (scrapperData.IFTTTNotify && product.Valid)
                {
                    bool productChanged = false;
                    if (!origproduct.Name.Equals(product.Name))
                    {
                        productChanged = true;
                        SendIFTTNotification("[" + origproduct.StoreName + "] " + origproduct.Name + "- Product Name changed!", "Orig: " + origproduct.Name + ", New: " + product.Name, product.Url);
                    }

                    if (!origproduct.Price.Equals(product.Price))
                    {
                        productChanged = true;
                        SendIFTTNotification("[" + origproduct.StoreName + "] " + origproduct.Name + "- Product Price changed!", "Orig: " + origproduct.Price + ", New: " + product.Price, product.Url);
                    }

                    if (!origproduct.Availability.Equals(product.Availability))
                    {
                        productChanged = true;
                        SendIFTTNotification("[" + origproduct.StoreName + "] " + origproduct.Name + "- Product Availability changed!", "Orig: " + origproduct.Availability + ", New: " + product.Availability, product.Url);
                    }

                    if (productChanged)
                    {
                        origproduct.CopyFrom(product);
                        ConfigurationToJSON(scrapperData, jsonFile);
                    }
                }
                else if (!product.Valid)
                {
                    Console.WriteLine("Unable to Scrappe: {0}.", product.Url);
                }
            }//);

            logger.Info("Sites Scanned at: " + DateTime.Now.ToString("MMM dd, yyyy - HH:mm:ss.fff"));
        }