本文整理汇总了Python中models.Product.popularity方法的典型用法代码示例。如果您正苦于以下问题:Python Product.popularity方法的具体用法?Python Product.popularity怎么用?Python Product.popularity使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Product
的用法示例。
在下文中一共展示了Product.popularity方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: fetch_category
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import popularity [as 别名]
def fetch_category(search_index, amazon_node_id):
api = caching.ResponseCachingAPI(
settings.AMAZON_AWS_KEY,
settings.AMAZON_SECRET_KEY,
settings.AMAZON_API_LOCALE,
settings.AMAZON_ASSOCIATE_TAG,
cachedir='cache',
cachetime=86400)
try:
for root in api.item_search(search_index, BrowseNode=str(amazon_node_id),
ResponseGroup=settings.AMAZON_RESPONSE_GROUP):
for item in root.Items.Item:
product = Product()
product.category = Category.objects.get(amazon_node_id=amazon_node_id)
product.asin = item.ASIN
product.title = unicode(item.ItemAttributes.Title)
product.detailpageurl = unicode(item.DetailPageURL)
product.manufacturer = unicode(getattr(item.ItemAttributes, 'Manufacturer', None))
product.publisher = unicode(getattr(item.ItemAttributes, 'Publisher', None))
product.brand = unicode(getattr(item.ItemAttributes, 'Brand', None))
product.popularity = getattr(item, 'SalesRank', 1000)
if hasattr(item, 'MediumImage'):
product.medium_image = getattr(item.MediumImage, 'URL', None)
if hasattr(item, 'LargeImage'):
product.large_image = getattr(item.LargeImage, 'URL', None)
if hasattr(item, 'EditorialReviews'):
product.description = unicode(getattr(item.EditorialReviews.EditorialReview, 'Content', None))
if hasattr(item.Offers, 'Offer'):
product.price = item.Offers.Offer.OfferListing.Price.FormattedPrice.pyval
elif hasattr(item.ItemAttributes, 'ListPrice'):
product.price = item.ItemAttributes.ListPrice.FormattedPrice.pyval
elif hasattr(item.OfferSummary, 'LowestUsedPrice'):
product.price = u'used from %s' % item.OfferSummary.LowestUsedPrice.FormattedPrice.pyval
else:
product.price = None
product.save()
except AWSError, e:
if e.code == 'AWS.ParameterOutOfRange':
pass # reached the api limit of 10 pages
else:
raise ValidationError(message=e.msg)