public override void Scrape() { while (!FoundItemInStock) { ConsoleOutputHelper.Write($"{StoreName} {ProductName} Checking...", Thread.CurrentThread); try { Html = GetHtml(); if (Html.Contains("add to cart", StringComparison.CurrentCultureIgnoreCase)) { SendSuccessMessage(); break; } ConsoleOutputHelper.Write($"{StoreName} {ProductName} [Not in stock. Trying again...]", ConsoleColor.Red, Thread.CurrentThread); CanScrape = true; } catch (Exception e) { ConsoleOutputHelper.Write(StoreName, e); CoolDown(); } Thread.Sleep(_waitTime); } }
public void SendText() { try { foreach (var texter in _texterList) { // T-Mobile blocks best buy links sent via text if (_url.Host.Contains("bestbuy", StringComparison.CurrentCultureIgnoreCase) && texter.Carrier == Carrier.TMOBILE) { string lhs = _url.AbsoluteUri.Substring(0, (int)_url.AbsoluteUri.Length / 2); string rhs = _url.AbsoluteUri.Substring((int)(_url.AbsoluteUri.Length / 2), (int)(_url.AbsoluteUri.Length / 2)); texter.Send("Found Item in stock", rhs + lhs); } else { texter.Send("Found item in stock!", _url.AbsoluteUri); } } } catch (Exception e) { ConsoleOutputHelper.Write(e); } }
public override void Scrape() { while (!FoundItemInStock) { ConsoleOutputHelper.Write($"{StoreName} {ProductName} Checking...", Thread.CurrentThread); try { Html = GetHtml(); if (Html.Contains("<button data-selenium=\"addToCartButton\"")) { SendSuccessMessage(); break; } CanScrape = true; ConsoleOutputHelper.Write($"{StoreName} {ProductName} [Not in stock. Trying again...]", ConsoleColor.Red, Thread.CurrentThread); } catch (Exception e) { ConsoleOutputHelper.Write(StoreName, e); CoolDown(); } Thread.Sleep(_waitTime); } }
static async Task Main(string[] args) { await ThreadBuilder.Start(); ConsoleOutputHelper.Write("No more items are being monitored.\nPress any key to close application"); System.Console.ReadKey(); }
public override void Scrape() { while (!FoundItemInStock) { ConsoleOutputHelper.Write($"{StoreName} {ProductName} Checking...", Thread.CurrentThread); try { Html = GetHtml(); if (!Html.Contains("<p class=\"product-out-of-stock\">Out of stock</p>")) { SendSuccessMessage(); break; } CanScrape = true; ConsoleOutputHelper.Write($"{StoreName} {ProductName} [Not in stock. Trying again...]", ConsoleColor.Red, Thread.CurrentThread); } catch (Exception e) { ConsoleOutputHelper.Write(StoreName, e); CoolDown(); } Thread.Sleep(_waitTime); } }
public override void Scrape() { while (!FoundItemInStock) { ConsoleOutputHelper.Write($"{StoreName} {ProductName} Checking...", Thread.CurrentThread); try { var doc = GetHtmlDocument(); Html = doc.Text; var addToCartButton = doc.QuerySelector("button[class*='add-to-cart-button']")?.InnerText.Trim() .ToLower(); if (Html.Contains("Add to Cart", StringComparison.CurrentCultureIgnoreCase) && !String.IsNullOrEmpty(addToCartButton)) { SendSuccessMessage(); break; } CanScrape = true; ConsoleOutputHelper.Write($"{StoreName} {ProductName} [Not in stock. Trying again...]", ConsoleColor.Red, Thread.CurrentThread); } catch (Exception e) { ConsoleOutputHelper.Write(StoreName, e); CoolDown(); } Thread.Sleep(_waitTime); } }
protected void SendSuccessMessage() { // We found an item in stock so lets send a text ConsoleOutputHelper.Write("[Found item in stock]: " + _url.AbsoluteUri, ConsoleColor.Green, Thread.CurrentThread); ConsoleOutputHelper.Write("Sending text...", Thread.CurrentThread); FoundItemInStock = true; SendText(); ConsoleOutputHelper.Write("Sent", Thread.CurrentThread); }
protected void CoolDown() { // If we threw another exception after the cool down is at 0 that means we need to wait longer if (!CanScrape) { // If this is a new timer, it will be at 0 and we need to then set it up if (_currentCoolDownTime == 0) { _currentCoolDownTime = _cooldownTime * 2; _cooldownTime = _currentCoolDownTime; } } CanScrape = false; ConsoleOutputHelper.Write($"{StoreName} {ProductName} is cooling down for {_cooldownTime} minutes...", Thread.CurrentThread); for (int i = _cooldownTime; i >= 0; i--) { ConsoleOutputHelper.Write($"{StoreName} {ProductName} is cooling down for {i} minutes...", Thread.CurrentThread); _currentCoolDownTime = i; Thread.Sleep(new TimeSpan(0, 1, 0)); } }