当前位置: 首页>>代码示例>>Python>>正文


Python Product.video方法代码示例

本文整理汇总了Python中models.Product.video方法的典型用法代码示例。如果您正苦于以下问题:Python Product.video方法的具体用法?Python Product.video怎么用?Python Product.video使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Product的用法示例。


在下文中一共展示了Product.video方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: crawl_product

# 需要导入模块: from models import Product [as 别名]
# 或者: from models.Product import video [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)
开发者ID:mobishift2011,项目名称:amzn,代码行数:63,代码来源:server.py


注:本文中的models.Product.video方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。