<s> import datetime <EOL> from itertools import islice <EOL> import bottlenose <EOL> from lxml import objectify , etree <EOL> import dateutil . parser <EOL> DOMAINS = { <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> '<STR_LIT>' : '<STR_LIT>' , <EOL> } <EOL> AMAZON_ASSOCIATES_BASE_URL = '<STR_LIT>' <EOL> class AmazonException ( Exception ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class CartException ( AmazonException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class CartInfoMismatchException ( CartException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class AsinNotFound ( AmazonException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class LookupException ( AmazonException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class SearchException ( AmazonException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class NoMorePages ( SearchException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class RequestThrottled ( AmazonException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class SimilartyLookupException ( AmazonException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class BrowseNodeLookupException ( AmazonException ) : <EOL> """<STR_LIT>""" <EOL> pass <EOL> class AmazonAPI ( object ) : <EOL> def __init__ ( self , aws_key , aws_secret , aws_associate_tag , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if '<STR_LIT>' in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = kwargs [ '<STR_LIT>' ] <EOL> del kwargs [ '<STR_LIT>' ] <EOL> if '<STR_LIT>' not in kwargs : <EOL> kwargs [ '<STR_LIT>' ] = '<STR_LIT>' <EOL> self . api = bottlenose . Amazon ( <EOL> aws_key , aws_secret , aws_associate_tag , ** kwargs ) <EOL> self . aws_associate_tag = aws_associate_tag <EOL> self . region = kwargs . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> def lookup ( self , ResponseGroup = "<STR_LIT>" , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> response = self . api . ItemLookup ( ResponseGroup = ResponseGroup , ** kwargs ) <EOL> root = objectify . fromstring ( response ) <EOL> if root . Items . Request . IsValid == '<STR_LIT:False>' : <EOL> code = root . Items . Request . Errors . Error . Code <EOL> msg = root . Items . Request . Errors . Error . Message <EOL> raise LookupException ( <EOL> "<STR_LIT>" . format ( code , msg ) ) <EOL> if not hasattr ( root . Items , '<STR_LIT>' ) : <EOL> raise AsinNotFound ( "<STR_LIT>" . format ( <EOL> etree . tostring ( root , pretty_print = True ) ) ) <EOL> if len ( root . Items . Item ) > <NUM_LIT:1> : <EOL> return [ <EOL> AmazonProduct ( <EOL> item , <EOL> self . aws_associate_tag , <EOL> self , <EOL> region = self . region ) for item in root . Items . Item <EOL> ] <EOL> else : <EOL> return AmazonProduct ( <EOL> root . Items . Item , <EOL> self . aws_associate_tag , <EOL> self , <EOL> region = self . region <EOL> ) <EOL> def lookup_bulk ( self , ResponseGroup = "<STR_LIT>" , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> response = self . api . ItemLookup ( ResponseGroup = ResponseGroup , ** kwargs ) <EOL> root = objectify . fromstring ( response ) <EOL> if not hasattr ( root . Items , '<STR_LIT>' ) : <EOL> return [ ] <EOL> return list ( <EOL> AmazonProduct ( <EOL> item , <EOL> self . aws_associate_tag , <EOL> self , <EOL> region = self . region ) for item in root . Items . Item <EOL> ) <EOL> def similarity_lookup ( self , ResponseGroup = "<STR_LIT>" , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> response = self . api . SimilarityLookup ( <EOL> ResponseGroup = ResponseGroup , ** kwargs ) <EOL> root = objectify . fromstring ( response ) <EOL> if root . Items . Request . IsValid == '<STR_LIT:False>' : <EOL> code = root . Items . Request . Errors . Error . Code <EOL> msg = root . Items . Request . Errors . Error . Message <EOL> raise SimilartyLookupException ( <EOL> "<STR_LIT>" . format ( <EOL> code , msg ) ) <EOL> return [ <EOL> AmazonProduct ( <EOL> item , <EOL> self . aws_associate_tag , <EOL> self . api , <EOL> region = self . region <EOL> ) <EOL> for item in getattr ( root . Items , '<STR_LIT>' , [ ] ) <EOL> ] <EOL> def browse_node_lookup ( self , ResponseGroup = "<STR_LIT>" , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> response = self . api . BrowseNodeLookup ( <EOL> ResponseGroup = ResponseGroup , ** kwargs ) <EOL> root = objectify . fromstring ( response ) <EOL> if root . BrowseNodes . Request . IsValid == '<STR_LIT:False>' : <EOL> code = root . BrowseNodes . Request . Errors . Error . Code <EOL> msg = root . BrowseNodes . Request . Errors . Error . Message <EOL> raise BrowseNodeLookupException ( <EOL> "<STR_LIT>" . format ( <EOL> code , msg ) ) <EOL> return [ AmazonBrowseNode ( node . BrowseNode ) for node in root . BrowseNodes ] <EOL> def search ( self , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> region = kwargs . get ( '<STR_LIT>' , self . region ) <EOL> kwargs . update ( { '<STR_LIT>' : region } ) <EOL> return AmazonSearch ( self . api , self . aws_associate_tag , ** kwargs ) <EOL> def search_n ( self , n , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> region = kwargs . get ( '<STR_LIT>' , self . region ) <EOL> kwargs . update ( { '<STR_LIT>' : region } ) <EOL> items = AmazonSearch ( self . api , self . aws_associate_tag , ** kwargs ) <EOL> return list ( islice ( items , n ) ) <EOL> def cart_create ( self , items , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if isinstance ( items , dict ) : <EOL> items = [ items ] <EOL> if len ( items ) > <NUM_LIT:10> : <EOL> raise CartException ( "<STR_LIT>" ) <EOL> offer_id_key_template = '<STR_LIT>' <EOL> quantity_key_template = '<STR_LIT>' <EOL> for i , item in enumerate ( items ) : <EOL> kwargs [ offer_id_key_template . format ( i ) ] = item [ '<STR_LIT>' ] <EOL> kwargs [ quantity_key_template . format ( i ) ] = item [ '<STR_LIT>' ] <EOL> response = self . api . CartCreate ( ** kwargs ) <EOL> root = objectify . fromstring ( response ) <EOL> return AmazonCart ( root ) <EOL> def cart_add ( self , items , CartId = None , HMAC = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not CartId or not HMAC : <EOL> raise CartException ( '<STR_LIT>' ) <EOL> if isinstance ( items , dict ) : <EOL> items = [ items ] <EOL> if len ( items ) > <NUM_LIT:10> : <EOL> raise CartException ( "<STR_LIT>" ) <EOL> offer_id_key_template = '<STR_LIT>' <EOL> quantity_key_template = '<STR_LIT>' <EOL> for i , item in enumerate ( items ) : <EOL> kwargs [ offer_id_key_template . format ( i ) ] = item [ '<STR_LIT>' ] <EOL> kwargs [ quantity_key_template . format ( i ) ] = item [ '<STR_LIT>' ] <EOL> response = self . api . CartAdd ( CartId = CartId , HMAC = HMAC , ** kwargs ) <EOL> root = objectify . fromstring ( response ) <EOL> new_cart = AmazonCart ( root ) <EOL> self . _check_for_cart_error ( new_cart ) <EOL> return new_cart <EOL> def cart_clear ( self , CartId = None , HMAC = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not CartId or not HMAC : <EOL> raise CartException ( '<STR_LIT>' ) <EOL> response = self . api . CartClear ( CartId = CartId , HMAC = HMAC , ** kwargs ) <EOL> root = objectify . fromstring ( response ) <EOL> new_cart = AmazonCart ( root ) <EOL> self . _check_for_cart_error ( new_cart ) <EOL> return new_cart <EOL> def cart_get ( self , CartId = None , HMAC = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not CartId or not HMAC : <EOL> raise CartException ( '<STR_LIT>' ) <EOL> response = self . api . CartGet ( CartId = CartId , HMAC = HMAC , ** kwargs ) <EOL> root = objectify . fromstring ( response ) <EOL> cart = AmazonCart ( root ) <EOL> self . _check_for_cart_error ( cart ) <EOL> return cart <EOL> def cart_modify ( self , items , CartId = None , HMAC = None , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> if not CartId or not HMAC : <EOL> raise CartException ( '<STR_LIT>' ) <EOL> if isinstance ( items , dict ) : <EOL> items = [ items ] <EOL> if len ( items ) > <NUM_LIT:10> : <EOL> raise CartException ( "<STR_LIT>" ) <EOL> cart_item_id_key_template = '<STR_LIT>' <EOL> quantity_key_template = '<STR_LIT>' <EOL> for i , item in enumerate ( items ) : <EOL> kwargs [ cart_item_id_key_template . format ( i ) ] = item [ '<STR_LIT>' ] <EOL> kwargs [ quantity_key_template . format ( i ) ] = item [ '<STR_LIT>' ] <EOL> response = self . api . CartModify ( CartId = CartId , HMAC = HMAC , ** kwargs ) <EOL> root = objectify . fromstring ( response ) <EOL> new_cart = AmazonCart ( root ) <EOL> self . _check_for_cart_error ( new_cart ) <EOL> return new_cart <EOL> def _check_for_cart_error ( self , cart ) : <EOL> if cart . _safe_get_element ( '<STR_LIT>' ) is not None : <EOL> error = cart . _safe_get_element ( <EOL> '<STR_LIT>' ) . text <EOL> if error == '<STR_LIT>' : <EOL> raise CartInfoMismatchException ( <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> '<STR_LIT>' <EOL> ) <EOL> raise CartException ( '<STR_LIT>' + error ) <EOL> class LXMLWrapper ( object ) : <EOL> def __init__ ( self , parsed_response ) : <EOL> self . parsed_response = parsed_response <EOL> def to_string ( self ) : <EOL> """<STR_LIT>""" <EOL> return etree . tostring ( self . parsed_response , pretty_print = True ) <EOL> def _safe_get_element ( self , path , root = None ) : <EOL> """<STR_LIT>""" <EOL> elements = path . split ( '<STR_LIT:.>' ) <EOL> parent = root if root is not None else self . parsed_response <EOL> for element in elements [ : - <NUM_LIT:1> ] : <EOL> parent = getattr ( parent , element , None ) <EOL> if parent is None : <EOL> return None <EOL> return getattr ( parent , elements [ - <NUM_LIT:1> ] , None ) <EOL> def _safe_get_element_text ( self , path , root = None ) : <EOL> """<STR_LIT>""" <EOL> element = self . _safe_get_element ( path , root ) <EOL> if element is not None : <EOL> return element . text <EOL> else : <EOL> return None <EOL> def _safe_get_element_date ( self , path , root = None ) : <EOL> """<STR_LIT>""" <EOL> value = self . _safe_get_element_text ( path = path , root = root ) <EOL> if value is not None : <EOL> try : <EOL> value = dateutil . parser . parse ( value ) <EOL> if value : <EOL> value = value . date ( ) <EOL> except ValueError : <EOL> value = None <EOL> return value <EOL> class AmazonSearch ( object ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , api , aws_associate_tag , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> self . kwargs = kwargs <EOL> self . current_page = <NUM_LIT:1> <EOL> self . api = api <EOL> self . aws_associate_tag = aws_associate_tag <EOL> def __iter__ ( self ) : <EOL> """<STR_LIT>""" <EOL> for page in self . iterate_pages ( ) : <EOL> for item in getattr ( page . Items , '<STR_LIT>' , [ ] ) : <EOL> yield AmazonProduct ( <EOL> item , self . aws_associate_tag , self . api , ** self . kwargs ) <EOL> def iterate_pages ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> while True : <EOL> yield self . _query ( ItemPage = self . current_page , ** self . kwargs ) <EOL> self . current_page += <NUM_LIT:1> <EOL> except NoMorePages : <EOL> pass <EOL> def _query ( self , ResponseGroup = "<STR_LIT>" , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> response = self . api . ItemSearch ( ResponseGroup = ResponseGroup , ** kwargs ) <EOL> root = objectify . fromstring ( response ) <EOL> if ( hasattr ( root . Items . Request , '<STR_LIT>' ) and <EOL> not hasattr ( root . Items , '<STR_LIT>' ) ) : <EOL> code = root . Items . Request . Errors . Error . Code <EOL> msg = root . Items . Request . Errors . Error . Message <EOL> if code == '<STR_LIT>' : <EOL> raise NoMorePages ( msg ) <EOL> elif code == '<STR_LIT>' : <EOL> raise RequestThrottled ( <EOL> "<STR_LIT>" . format ( code , msg ) ) <EOL> else : <EOL> raise SearchException ( <EOL> "<STR_LIT>" . format ( code , msg ) ) <EOL> return root <EOL> class AmazonBrowseNode ( LXMLWrapper ) : <EOL> @ property <EOL> def id ( self ) : <EOL> """<STR_LIT>""" <EOL> if hasattr ( self . parsed_response , '<STR_LIT>' ) : <EOL> return int ( self . parsed_response [ '<STR_LIT>' ] ) <EOL> return None <EOL> @ property <EOL> def name ( self ) : <EOL> """<STR_LIT>""" <EOL> return getattr ( self . parsed_response , '<STR_LIT:Name>' , None ) <EOL> @ property <EOL> def is_category_root ( self ) : <EOL> """<STR_LIT>""" <EOL> return getattr ( self . parsed_response , '<STR_LIT>' , False ) <EOL> @ property <EOL> def ancestor ( self ) : <EOL> """<STR_LIT>""" <EOL> ancestors = getattr ( self . parsed_response , '<STR_LIT>' , None ) <EOL> if hasattr ( ancestors , '<STR_LIT>' ) : <EOL> return AmazonBrowseNode ( ancestors [ '<STR_LIT>' ] ) <EOL> return None <EOL> @ property <EOL> def ancestors ( self ) : <EOL> """<STR_LIT>""" <EOL> ancestors = [ ] <EOL> node = self . ancestor <EOL> while node is not None : <EOL> ancestors . append ( node ) <EOL> node = node . ancestor <EOL> return ancestors <EOL> @ property <EOL> def children ( self ) : <EOL> """<STR_LIT>""" <EOL> children = [ ] <EOL> child_nodes = getattr ( self . parsed_response , '<STR_LIT>' ) <EOL> for child in getattr ( child_nodes , '<STR_LIT>' , [ ] ) : <EOL> children . append ( AmazonBrowseNode ( child ) ) <EOL> return children <EOL> class AmazonProduct ( LXMLWrapper ) : <EOL> """<STR_LIT>""" <EOL> def __init__ ( self , item , aws_associate_tag , api , * args , ** kwargs ) : <EOL> """<STR_LIT>""" <EOL> super ( AmazonProduct , self ) . __init__ ( item ) <EOL> self . aws_associate_tag = aws_associate_tag <EOL> self . api = api <EOL> self . parent = None <EOL> self . region = kwargs . get ( '<STR_LIT>' , '<STR_LIT>' ) <EOL> @ property <EOL> def price_and_currency ( self ) : <EOL> """<STR_LIT>""" <EOL> price = self . _safe_get_element_text ( <EOL> '<STR_LIT>' ) <EOL> if price : <EOL> currency = self . _safe_get_element_text ( <EOL> '<STR_LIT>' ) <EOL> else : <EOL> price = self . _safe_get_element_text ( <EOL> '<STR_LIT>' ) <EOL> if price : <EOL> currency = self . _safe_get_element_text ( <EOL> '<STR_LIT>' ) <EOL> else : <EOL> price = self . _safe_get_element_text ( <EOL> '<STR_LIT>' ) <EOL> currency = self . _safe_get_element_text ( <EOL> '<STR_LIT>' ) <EOL> if price : <EOL> fprice = float ( price ) / <NUM_LIT:100> if '<STR_LIT>' not in self . region else price <EOL> return fprice , currency <EOL> else : <EOL> return None , None <EOL> @ property <EOL> def offer_id ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element ( <EOL> '<STR_LIT>' ) <EOL> @ property <EOL> def asin ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def sales_rank ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def offer_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return "<STR_LIT>" . format ( <EOL> AMAZON_ASSOCIATES_BASE_URL . format ( domain = DOMAINS [ self . region ] ) , <EOL> self . asin , <EOL> self . aws_associate_tag ) <EOL> @ property <EOL> def author ( self ) : <EOL> """<STR_LIT>""" <EOL> authors = self . authors <EOL> if len ( authors ) : <EOL> return authors [ <NUM_LIT:0> ] <EOL> else : <EOL> return None <EOL> @ property <EOL> def authors ( self ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> authors = self . _safe_get_element ( '<STR_LIT>' ) <EOL> if authors is not None : <EOL> for author in authors : <EOL> result . append ( author . text ) <EOL> return result <EOL> @ property <EOL> def creators ( self ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> creators = self . _safe_get_element ( '<STR_LIT>' ) <EOL> if creators is not None : <EOL> for creator in creators : <EOL> role = creator . attrib [ '<STR_LIT>' ] if '<STR_LIT>' in creator . attrib else None <EOL> result . append ( ( creator . text , role ) ) <EOL> return result <EOL> @ property <EOL> def publisher ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def label ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def manufacturer ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def brand ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def isbn ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def eisbn ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def binding ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def pages ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def publication_date ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_date ( '<STR_LIT>' ) <EOL> @ property <EOL> def release_date ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_date ( '<STR_LIT>' ) <EOL> @ property <EOL> def edition ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def large_image_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def medium_image_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def small_image_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def tiny_image_url ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def reviews ( self ) : <EOL> """<STR_LIT>""" <EOL> iframe = self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> has_reviews = self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> if has_reviews and has_reviews == '<STR_LIT:true>' : <EOL> has_reviews = True <EOL> else : <EOL> has_reviews = False <EOL> return has_reviews , iframe <EOL> @ property <EOL> def ean ( self ) : <EOL> """<STR_LIT>""" <EOL> ean = self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> if ean is None : <EOL> ean_list = self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> if ean_list : <EOL> ean = self . _safe_get_element_text ( <EOL> '<STR_LIT>' , root = ean_list [ <NUM_LIT:0> ] ) <EOL> return ean <EOL> @ property <EOL> def upc ( self ) : <EOL> """<STR_LIT>""" <EOL> upc = self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> if upc is None : <EOL> upc_list = self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> if upc_list : <EOL> upc = self . _safe_get_element_text ( <EOL> '<STR_LIT>' , root = upc_list [ <NUM_LIT:0> ] ) <EOL> return upc <EOL> @ property <EOL> def color ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def sku ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def mpn ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def model ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def part_number ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def title ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def editorial_review ( self ) : <EOL> """<STR_LIT>""" <EOL> reviews = self . editorial_reviews <EOL> if reviews : <EOL> return reviews [ <NUM_LIT:0> ] <EOL> return '<STR_LIT>' <EOL> @ property <EOL> def editorial_reviews ( self ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> reviews_node = self . _safe_get_element ( '<STR_LIT>' ) <EOL> if reviews_node is not None : <EOL> for review_node in reviews_node . iterchildren ( ) : <EOL> content_node = getattr ( review_node , '<STR_LIT>' ) <EOL> if content_node is not None : <EOL> result . append ( content_node . text ) <EOL> return result <EOL> @ property <EOL> def languages ( self ) : <EOL> """<STR_LIT>""" <EOL> result = set ( ) <EOL> languages = self . _safe_get_element ( '<STR_LIT>' ) <EOL> if languages is not None : <EOL> for language in languages . iterchildren ( ) : <EOL> text = self . _safe_get_element_text ( '<STR_LIT:Name>' , language ) <EOL> if text : <EOL> result . add ( text . lower ( ) ) <EOL> return result <EOL> @ property <EOL> def features ( self ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> features = self . _safe_get_element ( '<STR_LIT>' ) <EOL> if features is not None : <EOL> for feature in features : <EOL> result . append ( feature . text ) <EOL> return result <EOL> @ property <EOL> def list_price ( self ) : <EOL> """<STR_LIT>""" <EOL> price = self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> currency = self . _safe_get_element_text ( <EOL> '<STR_LIT>' ) <EOL> if price : <EOL> return float ( price ) / <NUM_LIT:100> , currency <EOL> else : <EOL> return None , None <EOL> def get_attribute ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( "<STR_LIT>" . format ( name ) ) <EOL> def get_attribute_details ( self , name ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element ( "<STR_LIT>" . format ( name ) ) . attrib <EOL> def get_attributes ( self , name_list ) : <EOL> """<STR_LIT>""" <EOL> properties = { } <EOL> for name in name_list : <EOL> value = self . get_attribute ( name ) <EOL> if value is not None : <EOL> properties [ name ] = value <EOL> return properties <EOL> @ property <EOL> def parent_asin ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element ( '<STR_LIT>' ) <EOL> def get_parent ( self ) : <EOL> """<STR_LIT>""" <EOL> if not self . parent : <EOL> parent = self . _safe_get_element ( '<STR_LIT>' ) <EOL> if parent : <EOL> self . parent = self . api . lookup ( ItemId = parent ) <EOL> return self . parent <EOL> @ property <EOL> def browse_nodes ( self ) : <EOL> """<STR_LIT>""" <EOL> root = self . _safe_get_element ( '<STR_LIT>' ) <EOL> if root is None : <EOL> return [ ] <EOL> return [ AmazonBrowseNode ( child ) for child in root . iterchildren ( ) ] <EOL> @ property <EOL> def images ( self ) : <EOL> """<STR_LIT>""" <EOL> try : <EOL> images = [ image for image in self . _safe_get_element ( <EOL> '<STR_LIT>' ) ] <EOL> except TypeError : <EOL> images = [ ] <EOL> return images <EOL> @ property <EOL> def genre ( self ) : <EOL> """<STR_LIT>""" <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def actors ( self ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> actors = self . _safe_get_element ( '<STR_LIT>' ) or [ ] <EOL> for actor in actors : <EOL> result . append ( actor . text ) <EOL> return result <EOL> @ property <EOL> def directors ( self ) : <EOL> """<STR_LIT>""" <EOL> result = [ ] <EOL> directors = self . _safe_get_element ( '<STR_LIT>' ) or [ ] <EOL> for director in directors : <EOL> result . append ( director . text ) <EOL> return result <EOL> class AmazonCart ( LXMLWrapper ) : <EOL> """<STR_LIT>""" <EOL> @ property <EOL> def cart_id ( self ) : <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def purchase_url ( self ) : <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def amount ( self ) : <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def formatted_price ( self ) : <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def currency_code ( self ) : <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def hmac ( self ) : <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def url_encoded_hmac ( self ) : <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> def __len__ ( self ) : <EOL> return len ( self . _safe_get_element ( '<STR_LIT>' ) ) <EOL> def __iter__ ( self ) : <EOL> items = self . _safe_get_element ( '<STR_LIT>' ) <EOL> if items is not None : <EOL> for item in items : <EOL> yield AmazonCartItem ( item ) <EOL> def __getitem__ ( self , cart_item_id ) : <EOL> """<STR_LIT>""" <EOL> for item in self : <EOL> if item . cart_item_id == cart_item_id : <EOL> return item <EOL> raise KeyError ( '<STR_LIT>' . format ( cart_item_id , ) ) <EOL> class AmazonCartItem ( LXMLWrapper ) : <EOL> @ property <EOL> def asin ( self ) : <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def quantity ( self ) : <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def cart_item_id ( self ) : <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def title ( self ) : <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def product_group ( self ) : <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def formatted_price ( self ) : <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def amount ( self ) : <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) <EOL> @ property <EOL> def currency_code ( self ) : <EOL> return self . _safe_get_element_text ( '<STR_LIT>' ) </s>
