本文整理汇总了Python中models.Product.returned方法的典型用法代码示例。如果您正苦于以下问题:Python Product.returned方法的具体用法?Python Product.returned怎么用?Python Product.returned使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Product
的用法示例。
在下文中一共展示了Product.returned方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: crawl_product
# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import returned [as 别名]
def crawl_product(self, url, casin, ctx='', **kwargs):
r = req.get(url)
data = re.compile(r'parse_asin_\w+\((.*)\);$').search(r.text).group(1)
data = json.loads(data)
image_urls = []
for i in data['detailJSON']['main']['altviews']:
if i['zoomImage'] not in image_urls:
image_urls.append(i['zoomImage'])
if not image_urls:
for i in data['detailJSON']['asins']:
if i['asin'] == casin:
for j in i['altviews']:
if j['zoomImage'] not in image_urls:
image_urls.append(j['zoomImage'])
break
asin = data['detailJSON']['asin']
summary = data['productDescription']['shortProdDesc']
if data['productDescription']['bullets']:
list_info = [i.replace('"', '"').replace(''', '\'') for i in data['productDescription']['bullets'][0]['bulletsList']]
else:
list_info = []
brand = data['detailJSON']['brand']
returned = data['detailJSON']['returnPolicy']
# if 'intlShippable' in data['detailJSON']:
# shipping = 'international shipping' if data['detailJSON']['intlShippable'] == 1 else 'no international shipping'
# elif 'choices' in data['detailJSON']:
# for i in data['detailJSON']['choices']:
# if i['asin'] == casin:
# shipping = 'international shipping' if i['intlShippable'] == 1 else 'no international shipping'
# break
# shipping = shipping if shipping else ''
video = ''
for p in data['detailJSON']['asins']:
if p['asin'] == casin:
video = p['videos'][0]['url'] if p['videos'] else ''
break
is_new, is_updated = False, False
product = Product.objects(key=casin).first()
if not product:
is_new = True
product = Product(key=casin)
product.summary = summary
product.list_info = list_info
product.brand = brand
product.shipping = 'FAST, FREE SHIPPING, FREE RETURN SHIPPING in the U.S.'
product.returned = returned
product.video = video
product.image_urls = image_urls
product.full_update_time = datetime.utcnow()
if product.updated == False:
product.updated = True
ready = True
else: ready = False
product.save()
common_saved.send(sender=ctx, obj_type='Product', key=casin, url=url, is_new=is_new, is_updated=is_updated, ready=ready)