private void AddDbSneaker(DbRoot db, Listing listing, RootParsingObject shop, Shop shopCatalogItem) { log += "Add Sneaker. sku:" + listing.sku + " Title:" + listing.title + br; var sneaker = new DbSneaker(); sneaker.Id = db.Sneakers.Count + 1; sneaker.Brand = listing.brand; sneaker.Sku = listing.sku; sneaker.Titles.Add(listing.title); sneaker.Color = listing.colorbrand; sneaker.Category = listing.category; sneaker.Links.Add(listing.url); if (listing.images.Count > 0) { var imageCollection = new DbImageCollection(); imageCollection.ShopName = shop.market_info.name; foreach (var image in listing.images) { var dbimg = new DbImage(); dbimg.SiteUrl = image; imageCollection.Images.Add(dbimg); } //imageCollection.Images = listing.images; //todo менять ссылки из магазины на ссылки с нашего сервака //todo качать фотки в момент парсинга sneaker.ImageCollectionList.Add(imageCollection); } foreach (var size in listing.sizes) { var dbSize = GetDbSize(sneaker, size, listing, shop, shopCatalogItem); sneaker.Sizes.Add(dbSize); } db.Sneakers.Add(sneaker); }
private static DbOffer CreateDbOffer(DbSneaker sneaker, ListingSize size, Listing listing, RootParsingObject shop, Shop shopCatalogItem) { var deliveryUs = shopCatalogItem.delivery.Find(x => x.location == "US"); var offer = new DbOffer(); offer.url = listing.url; offer.price = listing.price; offer.old_price = listing.old_price; offer.currency = shopCatalogItem.currency; offer.stock_name = shop.market_info.name; offer.price_usd_with_delivery_to_usa_and_minus_vat = AllStockExporter.GetAllStockPrice(offer.price, offer.currency, deliveryUs.value, deliveryUs.vat); return(offer); }
private List <string> GetImages(DbSneaker dbSneaker) { if (dbSneaker.ImageCollectionList.Count == 0) { return(null); } var images = new List <string>(); var imgList = dbSneaker.ImageCollectionList[0].Images; foreach (var image in imgList) { images.Add(image.OurUrl); } return(images); //todo добавить сортировку изображений, чтобы показывать в первую очередь те фотки, которые лучше всего подходят под магазин (сначала из первого эшелона, потом из других магазинов и так далее }
private static DbSize GetDbSize(DbSneaker sneaker, ListingSize size, Listing listing, RootParsingObject shop, Shop shopCatalogItem) { var dbSize = new DbSize(); dbSize.Us = size.us; dbSize.Eu = size.eu; dbSize.Uk = size.uk; dbSize.Cm = size.cm; dbSize.Ru = size.ru; dbSize.Upc = size.upc; var offer = CreateDbOffer(sneaker, size, listing, shop, shopCatalogItem); dbSize.Offers.Add(offer); return(dbSize); }
private string GetBonanzaRecordDescription(DbSize dbSize, DbSneaker dbSneaker) { var boothUrl = System.Configuration.ConfigurationManager.AppSettings["bonanzaBoothUrlAllBrands"]; var title = dbSneaker.Titles[0]; var sku = dbSneaker.Sku; var size = dbSize.Us; if (string.IsNullOrWhiteSpace(size)) { _logger.Warn("Ошибка в размере. Размер пустой. sku: " + sku); return(null); } var sizeString = size + " US (" + dbSneaker.Category.ToUpper() + "'S)"; string description = "<h3 style=\"text-align: center;\"><strong>" + title.ToUpper() + "</strong></h3>" + "<h3 style=\"text-align: center;\"><strong>" + "STYLE: " + sku + "</strong></h3>" + "<h3 style=\"text-align: center;\"><strong>" + "SIZE: " + sizeString + "</strong></h3>" + "<h3 style=\"text-align: center;\"><strong>" + "100% AUTHENTIC" + "</strong></h3>" + "<h3 style=\"text-align: center;\"><strong>" + "WORLDWIDE SHIPPING FOR 5-10 DAYS IN DOUBLE BOX WITH TRACKING NUMBER.<br>" + "</strong></h3>" + "<h3 style=\"text-align: center;\"><strong>" + "SHIP IN 2 BUSINESS DAY." + "</strong></h3>"; description += "<h3 style=\"text-align: center;\"><strong>" + "Other sizes of this model available in out stock: " + "<a href=\"" + boothUrl + "?utf8=%E2%9C%93&item_sort_options%5Bfilter_string%5D=" + sku + "&item_sort_options%5Bfilter_category_id%5D=&item_sort_options%5Bcustom_category_id%5D=&commit=Go\" rel=\"nofollow\" target=\"_blank\">Link</a>" + "</strong></h3>"; description += "<h3 style=\"text-align: center;\"><strong>" + "Please feel free to ask any questions and see <a href=\"" + boothUrl + "\" rel=\"nofollow\" target=\"_blank\">all our listings</a> for more great deals." + "</strong></h3>"; //throw new NotImplementedException(); return(description); }
private BonanzaRecord GetBonanzaRecord(DbSneaker dbSneaker, DbSize dbSize) { var bRecord = new Model.BonanzaModel.BonanzaRecord(); //standart data bRecord.quantity = 5; bRecord.condition = "New with box"; bRecord.force_update = "true"; bRecord.brand = dbSneaker.Brand; //shipping bRecord.shipping_price = 29; bRecord.shipping_type = "flat"; bRecord.shipping_carrier = "usps"; bRecord.shipping_service = "EconomyShipping"; bRecord.shipping_package = "normal"; //bRecord.worldwide_shipping_type = "flat"; //bRecord.worldwide_shipping_price = 29; bRecord.id = dbSneaker.Sku + "-" + dbSize.Us; bRecord.description = GetBonanzaRecordDescription(dbSize, dbSneaker); if (bRecord.description == null) { _logger.Warn("Пустое описание. sku2:" + bRecord.id); return(null); } //todo поправить метод, так как пола теперь нет, только категория bRecord.category = GetBonanzaCategory(dbSneaker.Category, dbSneaker.Category); bRecord.width = GetBonanzaWidth(dbSneaker.Category); bRecord.title = GetTitle(dbSneaker.Brand, dbSize.Us, dbSneaker.Sku, dbSneaker.Titles[0], dbSneaker.Category); //price var offer = GetNonRussianOffer(dbSize); //отфильтруем русские магазы и берем самый дешевый оффер if (offer == null) { return(null); } bRecord.price = GetPrice(offer.price_usd_with_delivery_to_usa_and_minus_vat); //images List <string> images = GetImages(dbSneaker); if (images == null) { _logger.Warn("Нет изображений. sku2:" + bRecord.id); return(null); } if (images.Count == 0) { _logger.Warn("Нет изображений. sku2:" + bRecord.id); return(null); } bRecord.image1 = images[0]; if (images.Count > 1) { bRecord.image2 = images[1]; } if (images.Count > 2) { bRecord.image3 = images[2]; } if (images.Count > 3) { bRecord.image4 = images[3]; } bRecord.size = dbSize.Us; bRecord.traits = "[[US Size:" + dbSize.Us + "]] "; bRecord.upc = dbSize.Upc; bRecord.MPN = dbSneaker.Sku; //это вроде не работает bRecord.traits += "[[MPN:" + dbSneaker.Sku + "]] "; return(bRecord); }
private void UpdateDbSneaker(DbRoot db, DbSneaker sneaker, Listing listing, RootParsingObject shop, Shop shopCatalogItem) { log += "Update Sneaker. sku:" + sneaker.Sku + " title: " + sneaker.Titles[0] + br; /* логика: * проверяем заголовок, если длиннее, берем его * проверяем остальные элементы, если они не нул, а были нул то берем их * сравниваем категорию листинга и кроссовка, если не совпадают то отклоняем этот листинг (но по идее такого быть не должно */ //title var title = sneaker.Titles.Find(x => x.ToLower() == listing.title.ToLower()); if (title == null) { sneaker.Titles.Add(listing.title); sneaker.Titles = sneaker.Titles.OrderByDescending(x => x.Length).ToList(); } //color if (!string.IsNullOrWhiteSpace(listing.colorbrand)) { if (listing.colorbrand.Length > sneaker.Color.Length) { sneaker.Color = listing.colorbrand; } } //category //если пустая то добавляем if (string.IsNullOrWhiteSpace(sneaker.Category) && !string.IsNullOrWhiteSpace(listing.category)) { sneaker.Category = listing.category; } //если обе непустые сраванием else if (!string.IsNullOrWhiteSpace(sneaker.Category) && !string.IsNullOrWhiteSpace(listing.category)) { if (sneaker.Category != listing.category) { log += "Warn! Other categories. sku: " + sneaker.Sku + " sneaker.Category:" + sneaker.Category + " listing.category:" + listing.category + " listing.url: " + listing.url + br; } } //если обе пустые то else if (string.IsNullOrWhiteSpace(sneaker.Category) && string.IsNullOrWhiteSpace(listing.category)) { log += "Warn: category is empty" + br; } //links sneaker.Links.Add(listing.url); //images var imgCol = new DbImageCollection(); imgCol.ShopName = shopCatalogItem.name; foreach (var lImage in listing.images) { var dbImg = new DbImage(); dbImg.SiteUrl = lImage; imgCol.Images.Add(dbImg); } sneaker.ImageCollectionList.Add(imgCol); //sizes foreach (var lSize in listing.sizes) { //find size var snSize = new DbSize(); if (!string.IsNullOrWhiteSpace(lSize.us)) { snSize = sneaker.Sizes.Find(x => x.Us == lSize.us); //если размера нет, создаем if (snSize == null) { var dbSize = GetDbSize(sneaker, lSize, listing, shop, shopCatalogItem); sneaker.Sizes.Add(dbSize); } //если есть создаем только оффер else { var offer = CreateDbOffer(sneaker, lSize, listing, shop, shopCatalogItem); snSize.Offers.Add(offer); snSize.Offers = snSize.Offers.OrderBy(x => x.price_usd_with_delivery_to_usa_and_minus_vat) .ToList(); } } else { //если юс размера нет, то надо добисать будет код (например для асфальтгольда) throw new Exception("size us is null. Cannot update db sneaker."); } } }