private async Task <ScraperViewModel> ScrapeOne(INeweggScraperService scraperService, string url) { var viewModel = new ScraperViewModel { NumberOfSuccessfullyAdded = 0, NumberOfErrors = 0, }; var message = new ScraperViewModelMessage { Url = url, }; try { message.Message = await scraperService.ScrapeFromProductPageAsync(url); viewModel.NumberOfSuccessfullyAdded++; } catch (Exception exeption) { this.logger.LogWarning($"Exeption occured: {exeption.Message}."); viewModel.NumberOfErrors++; message.Message = exeption.Message; message.InnerExeption = exeption.InnerException.Message; } viewModel.Messages.Add(message); return(viewModel); }
public ActionResult Scraper() { List <ScraperViewModel> listShopScrap = new List <ScraperViewModel>(); using (sklepEntities db = new sklepEntities()) { var shopsScrap = db.Scrapers; foreach (Scrapers item in shopsScrap) { ScraperViewModel shpScrap = new ScraperViewModel(); shpScrap.ProductID = item.ProductID; shpScrap.XKomPrice = GetPriceFromScraper(item.XKomPrice, item.XKomLinkChecked); shpScrap.AlsenPrice = GetPriceFromScraper(item.AlsenPrice, item.AlsentLinkChecked); shpScrap.VobisPrice = GetPriceFromScraper(item.VobisPrice, item.VobistLinkChecked); shpScrap.CeneoPrice = GetPriceFromScraper(item.CeneoPrice, item.CeneoLinkChecked); shpScrap.LastUpdate = (DateTime)item.DateLastUpdate; if (item.DifferencePrice != null) { shpScrap.DifferencePrice = ((decimal)item.DifferencePrice).ToString("C2"); } listShopScrap.Add(shpScrap); } } return(View(listShopScrap)); }
private async Task <ScraperViewModel> ScrapeManyAsync(INeweggScraperService scraperService, string url, int pages) { var urls = this.neweggUrlScraper.GetUrlsForScrapingFromProducts(url, pages); var count = urls.Count; var counter = 0; var viewModel = new ScraperViewModel { NumberOfSuccessfullyAdded = 0, NumberOfErrors = 0, }; this.logger.LogInformation(string.Empty + count); foreach (var u in urls) { var message = new ScraperViewModelMessage { Url = u, }; try { message.Message = await scraperService.ScrapeFromProductPageAsync(u); viewModel.NumberOfSuccessfullyAdded++; } catch (Exception exeption) { this.logger.LogWarning($"Exeption occured: {exeption.Message}."); viewModel.NumberOfErrors++; message.Message = exeption.Message; message.InnerExeption = exeption.InnerException?.Message; } viewModel.Messages.Add(message); this.logger.LogInformation(string.Empty + (count - (++counter))); } return(viewModel); }