コード例 #1
0
ファイル: models.py プロジェクト: kwantopia/socialsaver
    def get_by_upc( self, upc ):
        query = ProductQuery.all().filter('upc =', upc)
        result = query.fetch(api_key)
        if result.total > 0:
            p = result.products[0]
        else:
            return None

        product, created = self.get_or_create(sku=p.sku)
        if created:
            product.product_id = p.product_id
            product.name = fix_signs(p.name)
            product.album_title = "" if getattr(p, 'album_title', "") is None else getattr(p, 'album_title', "")
            product.artist_name = "" if getattr(p, 'artist_name', "") is None else getattr(p, 'artist_name', "")
            product.sku_description = p.name if p.name else p.artist_name
            # get the lowest category in the hierarchy 
            product.category = Category.objects.get(category_id=p.category_path[-1]["id"])
            product.regular_price = p.regular_price
            product.sale_price = p.sale_price
            product.on_sale = p.on_sale
            product.new = p.new
            product.thumbnail_image = p.thumbnail_image
            product.medium_image = p.medium_image
            product.customer_review_average = p.customer_review_average
            product.customer_review_count = 0 if p.customer_review_count == None else p.customer_review_count
            product.url = "" if p.url is None else p.url
            product.cart_url = "" if p.add_to_cart_url is None else p.add_to_cart_url 
            product.save()
        return product 
コード例 #2
0
ファイル: models.py プロジェクト: kwantopia/socialsaver
    def get_by_product_id( self, product_id):
        query = ProductQuery.all().filter('product_id =', product_id)
        result = query.fetch(api_key)

        if result.total > 0:
            p = result.products[0]
        else:
            return None

        product, created = self.get_or_create(sku=p.sku)
        if created:
            product.name = fix_signs(p.name)
            product.album_title = "" if getattr(p, 'album_title', "") is None else getattr(p, 'album_title', "")
            product.artist_name = "" if getattr(p, 'artist_name', "") is None else getattr(p, 'artist_name', "")
            product.sku_description = p.name if p.name else p.artist_name

            product.url = "" if p.url is None else p.url
            product.cart_url = "" if p.add_to_cart_url is None else p.add_to_cart_url 
 
            product.save()
        return product
コード例 #3
0
ファイル: models.py プロジェクト: kwantopia/socialsaver
    def search(self, s, page=1, me=None):
        results = {} 

        # search by name, artist_name, short description
        query = ProductQuery.all().extend('name =', "%s*"%s).extend('album_title =', "%s*"%s).extend('artist_name =', "%s*"%s).extend('short_description =', "%s*"%s)
        result = query.fetch(api_key, page=page)
        if result.total > 0:
            results['total_pages'] = result.total_pages
            results['products'] = []
            for p in result.products:
                #print sku
                if len(p.category_path) == 0:
                    continue
                product, created = self.get_or_create(sku=p.sku)
                if created:
                    product.product_id = p.product_id
                    product.name = fix_signs(p.name)
                    product.album_title = "" if getattr(p, 'album_title', "") is None else getattr(p, 'album_title', "")
                    product.artist_name = "" if getattr(p, 'artist_name', "") is None else getattr(p, 'artist_name', "")
                    product.sku_description = p.name if p.name else p.artist_name
                    # get the lowest category in the hierarchy 
                    #print p.category_path
                    product.category = Category.objects.get(category_id=p.category_path[-1]["id"])
                    product.regular_price = p.regular_price
                    product.sale_price = p.sale_price
                    product.on_sale = p.on_sale
                    product.new = p.new
                    product.thumbnail_image = "" if p.thumbnail_image is None else p.thumbnail_image
                    product.medium_image = "" if p.medium_image is None else p.medium_image
                    product.customer_review_average = 0.0 if p.customer_review_average is None else p.customer_review_average
                    product.customer_review_count = 0 if p.customer_review_count == None else p.customer_review_count
                    product.url = "" if p.url is None else p.url
                    product.cart_url = "" if p.add_to_cart_url is None else p.add_to_cart_url 

                    product.save()
                results['products'].append(product.details(me))
                        
        return results
コード例 #4
0
ファイル: models.py プロジェクト: kwantopia/socialsaver
    def filter_category( self, cat_id, page=1, me=None):
        """
            :param cat_id: the BestBuy category ID
        """
        results = {} 

        query = ProductQuery.all().filter('category_path.id =', cat_id)
        result = query.fetch(api_key, page=page)
        if result.total > 0:
            results['total_pages'] = result.total_pages
            results['products'] = []
            for p in result.products:
                product, created = self.get_or_create(sku=p.sku)
                if created:
                    product.product_id = p.product_id
                    product.name = fix_signs(p.name)
                    product.album_title = "" if getattr(p, 'album_title', "") is None else getattr(p, 'album_title', "")
                    product.artist_name = "" if getattr(p, 'artist_name', "") is None else getattr(p, 'artist_name', "")
                    product.sku_description = p.name if p.name else p.artist_name
                    # get the lowest category in the hierarchy 
                    product.category = Category.objects.get(category_id=p.category_path[-1]["id"])
                    product.regular_price = p.regular_price
                    product.sale_price = p.sale_price
                    product.on_sale = p.on_sale
                    product.new = p.new
                    product.thumbnail_image = "" if p.thumbnail_image is None else p.thumbnail_image
                    product.medium_image = "" if p.medium_image is None else p.medium_image
                    product.customer_review_average = 0.0 if p.customer_review_average is None else p.customer_review_average
                    product.customer_review_count = 0 if p.customer_review_count == None else p.customer_review_count
                    product.url = "" if p.url is None else p.url
                    product.cart_url = "" if p.add_to_cart_url is None else p.add_to_cart_url 

                    product.save()
                results['products'].append(product.details(me))
                        
        return results
コード例 #5
0
#!/usr/bin/python
import os
import json
import time
import urllib2
import sys
from premix import ProductQuery

api_key='3xvhyc8utc852wrwhy34n8wk'

f2=open('products.txt','w')

product_query = ProductQuery.all().filter('search =', 'laptop')

results=product_query.fetch(api_key)

totalpages = results.total_pages
curpage = results.current_page

while (curpage < totalpages) :
	try:
 		cur_results = product_query.fetch(api_key, page=curpage)
        	begin = 1
		end =10 
        	curprod=begin
        	time.sleep(1)
		while curprod < end :
                	product = cur_results.products[curprod]
    			sku = product.sku
			webURL = 'http://api.remix.bestbuy.com/v1/products(sku='+str(sku)+')?format=json&apiKey=3xvhyc8utc852wrwhy34n8wk'
 			try: