public static void createNewJson(JsonReadWrite st) { Console.WriteLine("\nEnter the number of product you want to track"); string numProduct = Console.ReadLine(); st.GenerateJson(int.Parse(numProduct)); }
static void Main(string[] args) { JsonReadWrite st = new JsonReadWrite(); if (File.Exists(@"H:\TrackAmazonProduct-master\TrackAmazonProduct-master\ConsoleApplication1\ConsoleApplication1\product.json")) { Console.WriteLine("Product file exist do you want to create new product File? [y/n]"); ConsoleKeyInfo cki = Console.ReadKey(); if (cki.Key.ToString().ToLower().Equals("y")) { createNewJson(st); } } else { createNewJson(st); } object objJson = st.readFile(); int productCount = ((ConsoleApplication1.RootObject)objJson).product.Count; string[] productName = new string[productCount]; string[] productValue = new string[productCount]; bool sendMail = false; for (int k = 0; k < productCount; k++) { string url = ((ConsoleApplication1.RootObject)objJson).product[k].url; HttpClient httpClient = new HttpClient(); Task <string> html = httpClient.GetStringAsync(url); HtmlAgilityPack.HtmlDocument htmlDocument = new HtmlAgilityPack.HtmlDocument(); htmlDocument.LoadHtml(html.Result.ToString().Trim()); string nodeProduct = htmlDocument.DocumentNode.SelectNodes("//span[@id='productTitle']")[0].InnerText.ToString().Trim(); decimal nodePrice = Decimal.Parse(Regex.Replace(htmlDocument.DocumentNode.SelectNodes("//span[@id='priceblock_ourprice']")[0].InnerText.ToString().Trim().Replace(" ", ""), @"\s+", String.Empty), NumberStyles.Currency); if (nodePrice <= int.Parse(((ConsoleApplication1.RootObject)objJson).product[k].value)) { sendMail = true; productName[k] = nodeProduct; productValue[k] = nodePrice.ToString(); } } if (sendMail == true) { SendMail(String.Join(", ", productName), String.Join(", ", productValue)); } }