コード例 #1
0
    def do_item_lookup(self, group='Images,ItemAttributes,EditorialReview'):
        ''' Perform an ItemLookup operation.  Will raise an exception if asin is None or empty '''
        if self.asin == None or len(self.asin) == 0:
            raise(AwsSearchException("ASIN must be provided for do_item_lookup"))

        ''' Create and sign the URL.  For the AWS URL we must create the SearchIndex parameter '''
        search_params = {}
        search_params['IdType'] = 'ASIN'
        search_params['ItemId'] = self.asin
        search_params['ResponseGroup'] = group
        ''' And of course need the operation '''
        search_params['Operation'] = 'ItemLookup'

        aws_url = AwsUrl( 'GET', params = search_params, tag = self.tag, key = self.key, secret = self.secret )

        ''' Sign the URL '''
        url_signed = aws_url.signed_url()

        f = urlopen( url_signed )
        self.search_result_dom = parse(f)
        f.close()

        if self.search_result_dom != None:
            ''' Get what should be the only item and return it '''
            items = self.search_result_dom.getElementsByTagName('Item')
            if items == None:
                return None
            else:
                for i in items:
                    ''' Better be only one so assume there is.  If AWS gets
                        that broken then what could we do but return the first anyway? '''
                    return i
        else:
            return None
コード例 #2
0
    def do_search(self):
        '''
        Perform the search given the provided parameters.  The result is returned as
        a minidom object but it is probably more useful to use the other methods
        such as get_small_image, get_item_asin, get_detail_page_url, etc. than 
        to work with the raw dom result.

            NOTE:   The search might "succeed" in the sense that it returns some XML
                    but that doesn't mean it was truly successful.  One should always
                    call get_errors() to see if there were any errors 
        '''
         
        ''' Create and sign the URL.  For the AWS URL we must create the SearchIndex parameter '''
        self.search_params['SearchIndex'] = self.search_index
        ''' And the ResponseGroup 
            
            TODO: Should make parameter too but this could be default
        '''
        self.search_params['ResponseGroup'] ='Images,ItemAttributes'
        ''' And of course need the operation '''
        self.search_params['Operation'] = 'ItemSearch'

        aws_url = AwsUrl( 'GET', params = self.search_params, tag = self.tag, key = self.key, secret = self.secret )

        ''' Sign the URL '''
        url_signed = aws_url.signed_url()

        if self.verbose:
            print 'AWS URL: ', url_signed

        f = urlopen( url_signed )
        self.search_result_dom = parse(f)
        f.close()
           
        ''' NOTE:  There might be an error in the search.  The caller
            should check with get_errors
        ''' 
        return self.search_result_dom