def _create_offer_dictionary( self, response: HtmlResponse, data: Dict, ) -> Dict: offers = response.css('div[itemprop="offers"]') if len(offers) == 0: pass # TODO: Throw error. offer_objects = [] for o in offers: price = o.css('span[itemprop="price"]::text').get() valid_through = o.css('span[itemprop="validThrough"]::text').get() offer_objects.append( offer.Offer(price=float(price), valid_until=valid_through)) # Order to get the sales price. offer_objects.sort(key=lambda x: x.price) amount = offer_objects[0].price valid_until = offer_objects[0].valid_until # TODO: Add valid until. item = offer_item_loader.OfferItemLoader(response=response) \ .add_store_id(store_id=self.store_id) \ .add_sold_by(sold_by=self.sold_by) \ .add_amount( amount=str(amount), ).add_currency(currency=curreny.Currency.CAD.value) \ .add_availability( availability=availability.Availability.IN_STOCK.value, ).add_condition(condition=condition.Condition.NEW.value) \ .load_item() return item.get_dictionary()
def __get_price(self, response): offerLoader = offer_item_loader.OfferItemLoader(response=response) offerLoader.add_css( 'amount', ['#addToCartForm > input[name="price"]::attr(value)']) offerLoader.add_css('currency', [ 'section.pdp-section > meta[itemprop="priceCurrency"]::attr(content)' ]) return dict(offerLoader.load_item())
def __get_price(self, response): offerLoader = offer_item_loader.OfferItemLoader(response=response) offerLoader.add_css('amount', [ '#schemaorg-offer > div.price-module.clearfix > div.price-wrapper.price-extra-large > meta[itemprop="price"]::attr(content)' ]) offerLoader.add_css('currency', [ '#schemaorg-offer > div.price-module.clearfix > div.price-wrapper.price-extra-large > meta[itemprop="priceCurrency"]::attr(content)' ]) return dict(offerLoader.load_item())
def _create_offer_dictionary( self, response: HtmlResponse, data: Optional[Dict] = None, ) -> Dict: amount = str(data.get('SalesPrice') or data.get('RegularPrice')), if not amount: pass # TODO: If unable to find amount then log and return nothing. # TODO: Add valid until. item = offer_item_loader.OfferItemLoader(response=response) \ .add_store_id(store_id=self.store_id) \ .add_sold_by(sold_by=self.sold_by) \ .add_amount( amount=amount, ).add_currency(currency=curreny.Currency.CAD.value) \ .add_availability( availability=availability.Availability.IN_STOCK.value, ).add_condition(condition=condition.Condition.NEW.value) \ .load_item() return item.get_dictionary()
def __get_price(self, response, product_offers): offerLoader = offer_item_loader.OfferItemLoader(response=response) if product_offers and product_offers.get('price'): offerLoader.add_value(offer.Offer.KEY_AMOUNT, str(product_offers.get('price'))) else: offerLoader.add_css(offer.Offer.KEY_AMOUNT, [ 'span[itemprop=price]', 'div.css-k008qs.e1ufqjyx0 > span.css-rykmet.esdkp3p2 > span.css-2vqe5n.esdkp3p0', 'body > div.js-content > div:nth-child(1) > div > div > div.css-0.eewy8oa0 > div.css-1i2cfe3.eewy8oa2 > div.css-18f77yw.eewy8oa4 > div > div.css-0.e1cd9jig0 > div > div.css-mzzkn5.e1yn5b3f5 > div > div > div.css-k008qs.e1ufqjyx0 > span.css-rykmet.esdkp3p2 > span' ]) if product_offers and product_offers.get('priceCurrency'): offerLoader.add_value(offer.Offer.KEY_CURRENCY, product_offers.get('priceCurrency')) else: offerLoader.add_value(offer.Offer.KEY_CURRENCY, curreny.Currency.CAD.value) offerLoader.add_value(offer.Offer.KEY_DATETIME, [datetime.datetime.utcnow().isoformat()]) return dict(offerLoader.load_item())