示例#1
0
 def _cpsuc_effect(self, order_list):
     for order in order_list:
         # 获取校验参数
         if type(order) is dict and order.has_key(
                 'merchant') and order.has_key('orderId') and order.has_key(
                     'productList') and order.has_key('merchant'):
             exist_order = MongodbUtil.find_one('api',
                                                'cps',
                                                spec_or_id={
                                                    'orderId':
                                                    order.get('orderId'),
                                                    'merchant':
                                                    order.get('merchant')
                                                })
             if exist_order:
                 exist_order['status'] = 'successful'
                 exist_order['successfulTime'] = DateUtil.get_sys_time()
                 MongodbUtil.update(
                     'api',
                     'cps',
                     spec_or_id={'_id': exist_order.get('_id')},
                     document=exist_order)
                 continue
         else:
             continue
         order = self._fit_params(order)
         # 插入cps
         cps_id = MongodbUtil.insert('api', 'cps', order)
         if cps_id:
             self._event('cps_insert:%s' % cps_id)
示例#2
0
def clear_update_product():
    try:
        logger.info('[TIME: %s] METHOD: clear_update_product' %
                    DateUtil.get_sys_time())
        clear_product()
        update_priority()
    except Exception as e:
        logger.error('Clear and update product error: %s' % e.message)
示例#3
0
    def _fit_params(self, order):
        """获取符合格式的参数"""
        cpc_id = self.get_cookie('c_i') if self.get_cookie('c_i') else ''
        order['orderTime'] = DateUtil.get_sys_time()
        order['status'] = 'pendding'
        order_total_price = order.get('orderTotalPrice') if order.get(
            'orderTotalPrice') else 0.0
        if not order_total_price:
            for product in order.get('productList'):
                order_total_price += product.get('totalPrice')
            order['orderTotalPrice'] = order_total_price
        if cpc_id:
            order['cpcId'] = ObjectId(cpc_id)

        return order
示例#4
0
def save_overdue_cpc(overdue_product_id, product, cpc_list):
    """定期备份cpc跟踪点击数到overdueCpc集合中"""
    for cpc in cpc_list:
        overdue_cpc = {
            'cpcOverdueProductId': overdue_product_id,
            'webmaster': cpc.get('webmaster'),
            'merchant': cpc.get('merchant'),
            'adPositionId': cpc.get('adPositionId'),
            'clickTime': cpc.get('clickTime'),
            'clearTime': DateUtil.get_sys_time(),
            'takeEffect': cpc.get('takeEffect'),
        }
        overdue_cpc_id = MongodbUtil.insert('shopping', 'overdueCpc',
                                            overdue_cpc)
        if overdue_cpc_id:
            logger.info(
                'Insert overdue cpc from:%s to:%s successfully!!!' %
                (overdue_cpc.get('webmaster'), overdue_cpc.get('merchant')))
示例#5
0
    def emit(self, record):
        for toaddr in self.toaddrs:
            msg = MIMEMultipart()
            msg['From'] = self.fromaddr
            msg['To'] = toaddr
            msg['Subject'] = self.subject

            #添加邮件内容
            message = 'ERROR %s:[%s]|%s: %s' % (DateUtil.get_sys_time('%Y-%m-%d %H:%M:%S'), record.filename, record.lineno, record.message)
            txt = MIMEText(message)
            msg.attach(txt)

            #发送邮件
            smtp = smtplib.SMTP()
            smtp.connect(self.mailhost)
            smtp.login(self.username, self.password)
            smtp.sendmail(self.fromaddr, toaddr, msg.as_string())
            smtp.quit()
示例#6
0
 def insert_cpc(self, user_id, language, title, webmaster, merchant,
                category, url, meta_info, duration):
     """插入新增点击 takeEffect: 1(successful) 0(failed)"""
     cpc_document = {
         'uid': user_id,
         'merchant': merchant,
         'clickTime': DateUtil.get_sys_time(),
         'url': url,
         'takeEffect': 1,
         'webmaster': webmaster,
         'category': category,
         'language': language,
         'title': title,
         'metaInfo': meta_info,
         'duration': duration,
     }
     obj_id = MongodbUtil.insert('api', 'cpc', cpc_document)
     return obj_id
示例#7
0
def save_product_img(product, tag_dict, size):
    """下载产品图片并存入mongodb中"""
    file_name = product.get(tag_dict['image'])
    opener = urllib2.build_opener()
    response = opener.open(file_name)
    file_body = response.read()
    file_name = UploadUtil.upload_pic(file_name, file_body, size[0], size[1])
    image = {
        'productId': product.get('_id'),
        'version': DateUtil.get_sys_time(),
        'fileName': file_name,
        'width': size[0],
        'height': size[1],
    }
    image_id = MongodbUtil.insert('shopping', 'image', image)
    if image_id:
        logger.info('Save product\'s image: %s successfully!!!' % product.get(tag_dict['image']))
        return image_id
    else:
        logger.info('Save product\'s image: %s failed!!!' % product.get(tag_dict['image']))
        return None
示例#8
0
 def _cps_effect(self, merchant, order_list):
     """广告主订单成功,在联盟插入cps数据,确认cps生效"""
     cookie_value = ''
     for order in order_list:
         # 获取校验参数
         if type(order) is dict and order.has_key(
                 'merchant') and order.has_key('orderId') and order.has_key(
                     'productList') and order.has_key('merchant') and (
                         merchant == order.get('merchant')):
             exist_order = MongodbUtil.find_one('api',
                                                'cps',
                                                spec_or_id={
                                                    'orderId':
                                                    order.get('orderId'),
                                                    'merchant':
                                                    order.get('merchant')
                                                })
             if exist_order:
                 exist_order['status'] = 'successful'
                 exist_order['successfulTime'] = DateUtil.get_sys_time()
                 MongodbUtil.update(
                     'api',
                     'cps',
                     spec_or_id={'_id': exist_order.get('_id')},
                     document=exist_order)
                 continue
         else:
             continue
         order = self._fit_params(order)
         # 插入cps
         cps_id = MongodbUtil.insert('api', 'cps', order)
         if cps_id:
             self._event('cps_insert:%s' % cps_id)
             cookie_value += '_%s' % cps_id.__str__()
     if cookie_value:
         self.set_cookie('c_i_l',
                         cookie_value,
                         expires_days=settings.cookie_alive_time)
示例#9
0
 def _update_cps_status(self):
     """更新订单状态为成功"""
     self._event('update_status')
     cps_id_str = self.get_cookie('c_i_l')
     cps_id_list = cps_id_str.split('_') if cps_id_str else list()
     for cps_id in cps_id_list:
         if cps_id:
             cps_document = MongodbUtil.find_one(
                 'api', 'cps', spec_or_id={'_id': ObjectId(cps_id)})
             if cps_document:
                 cps_document['status'] = 'successful'
                 cps_document['successfulTime'] = DateUtil.get_sys_time()
                 MongodbUtil.update(
                     'api',
                     'cps',
                     spec_or_id={'_id': cps_document.get('_id')},
                     document=cps_document)
     self.set_cookie('c_i_l', '', expires_days=settings.cookie_alive_time)
     result_info = {
         'status': '200',
         'message': 'successful',
     }
     self.write(json_encode(result_info))
示例#10
0
 def get_session_id(cls):
     current_time = DateUtil.get_sys_time(format_str='%Y-%m-%d %H:%M:%S')
     session_id = hashlib.md5(current_time).hexdigest()
     return session_id