コード例 #1
0
ファイル: import_product.py プロジェクト: iwangkang/affiliate
def do_import_product(product, tag_dict):
    """导入商品相关信息"""
    try:
        merchant_name = product.get(tag_dict['merchant'])
        merchant_list = get_merchant_list()
        if merchant_name not in merchant_list:
            return
        merchant = MongodbUtil.find_one('shopping', 'merchant', {'name': merchant_name})
        keyword_set = get_keyword_set(product, tag_dict)
        p = get_product_dict(product, keyword_set, merchant.get('_id'), tag_dict)
        # 插入或更新商品
        product['_id'], update_flag = MongodbUtil.update_or_insert('shopping', 'product', p, {"productId": p.get('productId'), 'merchantId': p.get('merchantId')})
        if product['_id']:
            if update_flag:
                logger.info('Update product: %s successfully!!!' % p.get('title'))
            else:
                logger.info('Save product: %s successfully!!!' % p.get('title'))
                # 遍历keywordList更新倒排索引
                save_keyword_index(keyword_set, product)
                # 下载产品图片
                for type, size in settings.image_size_list.items():
                    do_import_image(product, tag_dict, size)
        else:
            logger.error('Save product: %s failed!!!' % p.get('title'))
    except Exception as e:
        logger.error('[message: %s]; [params: %s]' % (e.message, product.__str__()))
コード例 #2
0
def import_merchant(merchant_name):
    """导入广告主"""
    try:
        import_flag = False
        if merchant_name:
            merchant_id, update_flag = MongodbUtil.update_or_insert(
                'shopping', 'merchant', {'name': merchant_name},
                {'name': merchant_name})
            if merchant_id:
                import_flag = True
                if update_flag:
                    logger.info('Update merchant: %s successfully!!!' %
                                merchant_name)
                else:
                    logger.info('Save merchant: %s successfully!!!' %
                                merchant_name)
            else:
                logger.info('Save merchant: %s failed!!!' % merchant_name)
        return import_flag
    except Exception as e:
        logger.error(e.message)