Exemplo n.º 1
0
 def get_item_imagesets(self, asin):
     response = self.amazon.ItemLookup(ItemId=asin, ResponseGroup='Images')
     res_x = xml_fix.fromstring(response)
     success = res_x.find('Items/Request/IsValid').text == 'True'
     if success:
         covers_x = {}
         image_x = res_x.find('Items/Item/ImageSets')
         if (image_x is not None) and len(image_x):
             front_x = image_x.find("ImageSet[@Category='primary']")
             if front_x is not None:
                 covers_x[ImageType.FrontCover] = front_x
             back_x = image_x.find("ImageSet[@Category='variant']")
             if back_x is not None:
                 covers_x[ImageType.BackCover] = back_x
         return covers_x
     else:
         return None
Exemplo n.º 2
0
    def search(self, keywords):
        # Perform Query by UPC or Other String
        # This process will search for items on Amazon using a set of keywords or a UPC

        # sample keyword (upc): '851147006055'
        response = self.amazon.ItemSearch(Keywords=keywords, SearchIndex='All')
        with open('debug.txt', 'w') as debug_file:
            debug_file.write(response)
        res_x = xml_fix.fromstring(response)
        success = res_x.find('Items/Request/IsValid').text == 'True'
        if success:
            items_x = res_x.findall('Items/Item')
            items = []
            for item_x in items_x:
                items.append(self._xml_to_dict(item_x))
            return items
        else:
            return None
Exemplo n.º 3
0
    def lookup(self, item_id, id_type='ASIN', return_xml=False):
        # Perform Query by single-item ID (assumes only one matching item, default type is ASIN)

        # sample ASIN: 'B00LOWJ6JY'
        print item_id, id_type
        if id_type == 'ASIN':
            response = self.amazon.ItemLookup(ItemId=item_id, IdType=id_type)
        else:
            response = self.amazon.ItemLookup(ItemId=item_id, IdType=id_type, SearchIndex='All')
        with open('debug.txt', 'w') as debug_file:
            debug_file.write(response)
        res_x = xml_fix.fromstring(response)
        success = res_x.find('Items/Request/IsValid').text == 'True'
        if success:
            item_x = res_x.find('Items/Item')
            if return_xml:
                return item_x
            else:
                return self._xml_to_dict(item_x)
        else:
            return None