def get_price_from_listing(self, listing): try: return float(dsearch(listing, 'LandedPrice')[0]['Amount']['value']) except ValueError: return dsearch(listing, 'LandedPrice')[0]['Amount']['value'] except (KeyError, IndexError): return None
def get_offerings_from_product(self, product): offerings = dsearch(product, 'LowestOfferListing') try: if isinstance(offerings[0], list): return offerings[0] else: return offerings except IndexError as e: raise KeyError('Offerrings not found.')
def get_seller_from_listing(self, listing): try: return dsearch(listing, 'FulfillmentChannel')[0]['value'] except (KeyError, IndexError): return None
def get_asin_from_product(self, product): try: return dsearch(product, 'ASIN')[0]['value'] except IndexError as e: raise KeyError("ASIN doesn't exist")
def get_products_from_response(self): if isinstance(self.response, dict): return [dsearch(self.response, 'Product')] else: return [dsearch(item, 'Product') for item in self.response]