本文整理汇总了Python中models.Product.soldout方法的典型用法代码示例。如果您正苦于以下问题:Python Product.soldout方法的具体用法?Python Product.soldout怎么用?Python Product.soldout使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Product
的用法示例。
在下文中一共展示了Product.soldout方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _parse_product
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import soldout [as 别名]
def _parse_product(self, event_id, asins, cAsins, prefix_url, product_data, ctx):
""" no video info, list_info, summary
:param event_id: this product belongs to the event's id
:param asins: all asins info in this event
:param cAsins: all casins info in this event
:param prefix_url: image and js prefix_url, probably 'http://z-ecx.images-amazon.com/images/I/'
:param product_data: product data in this product
"""
asin = product_data['asin']
casin = product_data['cAsin']
title = product_data['title'].encode('utf-8') # color is in title
# image_urls = [product_data['image']] + product_data['altImages'] # one picture, altImages is []
if 'listPrice' in product_data:
listprice = product_data['listPrice']['display'] # or 'amount', if isRange: True, don't know what 'amount' will be
else: listprice = ''
price = product_data['ourPrice']['display']
sizes = []
if product_data['teenagers']: # no size it is {}
for k, v in product_data['teenagers'].iteritems():
if v['size'] not in sizes: sizes.append(v['size'])
# tag is not precision. e.g. a bag is in shoes
# tag = product_data['productGL'] if 'productGL' in product_data else '' # 'apparel', 'home', 'jewelry', ''
soldout_link = 'http://www.myhabit.com/request/getBuyableAsinInfo?asin={0}&saleId={1}&flavor=parent&sid=177-4704555-7345351'.format(asin, event_id)
# one soldout link contains this asin's all color.
ret = req.get(soldout_link)
jsdata = json.loads(ret.content)
key_list = sorted(jsdata['buyableAsin'].keys())
len_sizes = len(sizes)
soldout = False
if len_sizes == 0:
if jsdata['buyableAsin'][casin]['stats']['remaining']['claimed'] == 0:
soldout = True
else:
soldout = False
else: # more than one size.
if 'asin' in key_list: key_list.remove('asin')
if 'privateSaleID' in key_list: key_list.remove('privateSaleID')
count = 0
for l in key_list:
if l == casin or (count > 0 and count < len_sizes):
count += 1
if jsdata['buyableAsin'][l]['stats']['remaining']['claimed'] == 0:
soldout = True
else:
soldout = False
break
# if casin in cAsins and 'soldOut' in cAsins[casin] and cAsins[casin]['soldOut'] == 1:
# soldout = True
# else: soldout = False
jslink = prefix_url + asins[asin]['url'] if asin in asins else ''
combine_url = 'http://www.myhabit.com/homepage#page=d&sale={0}&asin={1}&cAsin={2}'.format(event_id, asin, casin)
is_new, is_updated = False, False
product = Product.objects(key=casin).first()
if not product:
is_new = True
product = Product(key=casin)
product.combine_url = combine_url
product.asin = asin
product.title = title
# product.image_urls = image_urls
product.listprice = listprice
product.price = price
product.sizes = sizes
product.soldout = soldout
product.updated = False
else:
if soldout and product.soldout != soldout:
product.soldout = True
is_updated = True
product.update_history.update({ 'soldout': datetime.utcnow() })
if product.title != title:
product.title = title
product.update_history.update({ 'title': datetime.utcnow() })
if product.combine_url != combine_url:
product.combine_url = combine_url
product.update_history.update({ 'combine_url': datetime.utcnow() })
if product.listprice != listprice:
product.listprice = listprice
product.update_history.update({ 'listprice': datetime.utcnow() })
if product.price != price:
product.price = price
product.update_history.update({ 'price': datetime.utcnow() })
if event_id not in product.event_id: product.event_id.append(event_id)
product.jslink = jslink
product.list_update_time = datetime.utcnow()
product.save()
common_saved.send(sender=ctx, obj_type='Product', key=casin, url=product.combine_url, is_new=is_new, is_updated=is_updated)
return casin