Beispiel #1
0
    def find(self, product):
        try:
            apiki_buscape = BP(applicationID=BUSCAPE_APP_ID)
            apiki_buscape.set_sandbox()

            product = self._remove_accents(product)

            bp_offers = apiki_buscape.find_offer_list(keyword=product.replace(' ',','), format='json')
            bp_offers = bp_offers.get('data')
            bp_offers = json.loads(bp_offers)

            offers = []
            for bp_offer in bp_offers['offer']:
                offer = {}
                offer['product'] = bp_offer['offer']['offername']
                offer['seller'] = bp_offer['offer']['seller']['sellername']
                offer['currency'] = bp_offer['offer']['price']['currency']['abbreviation']
                offer['price'] = bp_offer['offer']['price']['value']
                
                if 'thumbnail' in bp_offer['offer']:
                    offer['thumbnail'] = bp_offer['offer']['thumbnail']['url']

                for link in bp_offer['offer']['links']:
                    offer['url'] = link['link']['url']
                    break

                offers.append(offer)

            return offers

        except Exception as e:
            return []
def quero_fazer(request):
    
    buscape = Buscape(BUSCAPE_APP_ID)

    searchWord = request.POST[SEARCH_PARAM]

    productService = ProductService.objects(name=searchWord).first()

    for item in productService.items :
        
        logger.info(u"Querying Buscapé for %s" % item.name)
        offer = buscape.find_offer_list(keyword=item.name).offer[0].offer

        item.price = offer.price.value
        item.thumbnail = offer.thumbnail.url
        item.seller = offer.seller.sellername
    
    return render_to_response(EDIT_HTML, dict(productService=productService))
    def setUp(self):
        
        buscape = Buscape(BUSCAPE_APP_ID)

        self.response = buscape.find_offer_list(keyword='picanha')