Example #1
0
    def collect_report(self):
        """搜集报表数据"""

        start_date = self.today - datetime.timedelta(days=1)
        end_date = start_date
        logger.info('start collect report')
        for shop in self.shop_list:
            logger.info('正在抓取帐号 %s 的报表信息' % shop['nick'])
            try:
                shop_report = RptSumSearchService.cust_rpt_sum_search(shop['nick'], shop['sid'], start_date, end_date,\
                        {'base':True, 'effect':True}, True, shop)
                multi_shop_report = RptSumSearchService.cust_rpt_sum_search(shop['nick'], shop['sid'], \
                        end_date - datetime.timedelta(days=shop['days']), end_date,\
                        {'base':True, 'effect':True}, True, shop)
                
                #目前使用API获取,以后可以改用使用db
                campaigns = SimbaCampaignsGet.get_campaign_list(shop['access_token'], shop['nick'])
                campaigns_id = []
                campaigns_dict = {}
                for campaign in campaigns:
                    campaign = campaign.toDict()
                    campaigns_id.append(campaign['campaign_id'])
                    campaigns_dict[campaign['campaign_id']] = campaign
                
                campaigns_report = RptSumSearchService.camp_rpt_sum_search(campaigns_id, shop['nick'], \
                        shop['sid'], start_date, end_date, {'base':True, 'effect':True}, True, shop)
                multi_campaigns_report = RptSumSearchService.camp_rpt_sum_search(campaigns_id, shop['nick'], \
                        shop['sid'], end_date - datetime.timedelta(days=shop['days']), end_date, \
                        {'base':True, 'effect':True}, True, shop)
            except InvalidAccessTokenException,e:
                logger.error('%s : InvalidAccessTokenException' % (shop['nick']))
                continue
            except Exception,e:
                continue
Example #2
0
    def collect_report(self):
        """搜集报表数据"""

        start_date = self.today - datetime.timedelta(days=1)
        end_date = start_date
        logger.info('start collect report')
        for shop in self.shop_list:
            logger.info('正在抓取帐号 %s 的报表信息' % shop['nick'])
            try:
                shop_report = RptSumSearchService.cust_rpt_sum_search(shop['nick'], shop['sid'], start_date, end_date,\
                        {'base':True, 'effect':True}, True, shop)
                multi_shop_report = RptSumSearchService.cust_rpt_sum_search(shop['nick'], shop['sid'], \
                        end_date - datetime.timedelta(days=shop['days']), end_date,\
                        {'base':True, 'effect':True}, True, shop)

                #目前使用API获取,以后可以改用使用db
                campaigns = SimbaCampaignsGet.get_campaign_list(
                    shop['access_token'], shop['nick'])
                campaigns_id = []
                campaigns_dict = {}
                for campaign in campaigns:
                    campaign = campaign.toDict()
                    campaigns_id.append(campaign['campaign_id'])
                    campaigns_dict[campaign['campaign_id']] = campaign

                campaigns_report = RptSumSearchService.camp_rpt_sum_search(campaigns_id, shop['nick'], \
                        shop['sid'], start_date, end_date, {'base':True, 'effect':True}, True, shop)
                multi_campaigns_report = RptSumSearchService.camp_rpt_sum_search(campaigns_id, shop['nick'], \
                        shop['sid'], end_date - datetime.timedelta(days=shop['days']), end_date, \
                        {'base':True, 'effect':True}, True, shop)
            except InvalidAccessTokenException, e:
                logger.error('%s : InvalidAccessTokenException' %
                             (shop['nick']))
                continue
            except Exception, e:
                continue
Example #3
0
class CollectReport:
    def __init__(self, date):
        self.today = date
        header = u'账户,计划,当天ROI,当天花费,成交额,当天点击,平均点击花费,成交笔数,收藏,当天转化率,多天ROI,多天花费,多天成交额,多天收藏,天数,店铺id\n'
        self.header = header.encode('utf-8')
        self.shop_list = self.get_shop_list()
        self.report_list = []

    def get_shop_list(self):
        """此方法必须被继承
        shop 信息 应包含 sid nick access_token subway_token 特殊计划id 等"""

        return []

    def _load_syb_user(self):
        syb_user = {}
        file_data = file(
            '/home/zhoujiebing/SYB/Webpage/longtail/report/data/syb_user.csv'
        ).read().split('\n')
        for line in file_data:
            order = line.split(',')
            if len(order) < 2:
                continue
            nick = order[0]
            order_start = parser_string_to_date(order[1])
            days_delta = (self.today - order_start).days
            if days_delta > 1:
                syb_user[nick] = min(days_delta, 15)
            #提前续订的
            elif days_delta < 0:
                syb_user[nick] = 15
        return syb_user

    def collect_report(self):
        """搜集报表数据"""

        start_date = self.today - datetime.timedelta(days=1)
        end_date = start_date
        logger.info('start collect report')
        for shop in self.shop_list:
            logger.info('正在抓取帐号 %s 的报表信息' % shop['nick'])
            try:
                shop_report = RptSumSearchService.cust_rpt_sum_search(shop['nick'], shop['sid'], start_date, end_date,\
                        {'base':True, 'effect':True}, True, shop)
                multi_shop_report = RptSumSearchService.cust_rpt_sum_search(shop['nick'], shop['sid'], \
                        end_date - datetime.timedelta(days=shop['days']), end_date,\
                        {'base':True, 'effect':True}, True, shop)

                #目前使用API获取,以后可以改用使用db
                campaigns = SimbaCampaignsGet.get_campaign_list(
                    shop['access_token'], shop['nick'])
                campaigns_id = []
                campaigns_dict = {}
                for campaign in campaigns:
                    campaign = campaign.toDict()
                    campaigns_id.append(campaign['campaign_id'])
                    campaigns_dict[campaign['campaign_id']] = campaign

                campaigns_report = RptSumSearchService.camp_rpt_sum_search(campaigns_id, shop['nick'], \
                        shop['sid'], start_date, end_date, {'base':True, 'effect':True}, True, shop)
                multi_campaigns_report = RptSumSearchService.camp_rpt_sum_search(campaigns_id, shop['nick'], \
                        shop['sid'], end_date - datetime.timedelta(days=shop['days']), end_date, \
                        {'base':True, 'effect':True}, True, shop)
            except InvalidAccessTokenException, e:
                logger.error('%s : InvalidAccessTokenException' %
                             (shop['nick']))
                continue
            except Exception, e:
                continue
            self.report_list.append(
                Report.merge_report(shop_report[0], multi_shop_report[0],
                                    shop))
            for i in range(len(campaigns_id)):
                if campaigns_report[i]['campaignid'] != multi_campaigns_report[
                        i]['campaignid']:
                    logger.info('%s 出现单体计划报表与多天计划报表不一致' % shop['nick'])
                self.report_list.append(
                    Report.merge_report(
                        campaigns_report[i], multi_campaigns_report[i], shop,
                        campaigns_dict[campaigns_report[i]['campaignid']]))
Example #4
0
                continue
            except Exception, e:
                continue
            self.report_list.append(
                Report.merge_report(shop_report[0], multi_shop_report[0],
                                    shop))
            for i in range(len(campaigns_id)):
                if campaigns_report[i]['campaignid'] != multi_campaigns_report[
                        i]['campaignid']:
                    logger.info('%s 出现单体计划报表与多天计划报表不一致' % shop['nick'])
                self.report_list.append(
                    Report.merge_report(
                        campaigns_report[i], multi_campaigns_report[i], shop,
                        campaigns_dict[campaigns_report[i]['campaignid']]))

        logger.info('finish collect report')


class CollectSYBReport(CollectReport):
    def __init__(self, date):
        self.soft_code = 2
        CollectReport.__init__(self, date)
        set_taobao_client('12685542', '6599a8ba3455d0b2a043ecab96dfa6f9')

    def get_shop_list(self):
        """获取省油宝 shop_list"""

        time_now = datetime.datetime.now()
        shop_list = []
        shop_status_list = Shop.get_all_normal_shop_status(self.soft_code)
        shop_info_list = Shop.get_all_shop_info(self.soft_code)
Example #5
0
                        shop['sid'], start_date, end_date, {'base':True, 'effect':True}, True, shop)
                multi_campaigns_report = RptSumSearchService.camp_rpt_sum_search(campaigns_id, shop['nick'], \
                        shop['sid'], end_date - datetime.timedelta(days=shop['days']), end_date, \
                        {'base':True, 'effect':True}, True, shop)
            except InvalidAccessTokenException,e:
                logger.error('%s : InvalidAccessTokenException' % (shop['nick']))
                continue
            except Exception,e:
                continue
            self.report_list.append(Report.merge_report(shop_report[0], multi_shop_report[0], shop))
            for i in range(len(campaigns_id)):
                if campaigns_report[i]['campaignid'] != multi_campaigns_report[i]['campaignid']:
                    logger.info('%s 出现单体计划报表与多天计划报表不一致' % shop['nick'])
                self.report_list.append(Report.merge_report(campaigns_report[i], multi_campaigns_report[i], shop, campaigns_dict[campaigns_report[i]['campaignid']]))
        
        logger.info('finish collect report')
            

class CollectSYBReport(CollectReport):

    def __init__(self, date):
        self.soft_code = 2
        CollectReport.__init__(self, date)
        set_taobao_client('12685542', '6599a8ba3455d0b2a043ecab96dfa6f9')

    def get_shop_list(self):
        """获取省油宝 shop_list"""

        time_now = datetime.datetime.now()
        shop_list = []
        shop_status_list = Shop.get_all_normal_shop_status(self.soft_code)