Ejemplo n.º 1
0
def delete_ads_in_active_campaigns():
    campaign_set = get_ads_paused_campaigns()
    campaign_set_cmd = list()
    for i in range(0, len(campaign_set)):
        campaign_set_cmd.append("DELETED")
    log.logger.info("准备删除" + str(len(campaign_set)) + "个 ads 状态为inactive的广告。")
    ntp.control_campaign(campaign_set, campaign_set_cmd)
Ejemplo n.º 2
0
def delete_pending_campaigns():
    campaign_set = get_pending_view_campaigns()
    campaign_set_cmd = list()
    for i in range(0, len(campaign_set)):
        campaign_set_cmd.append("DELETED")
    log.logger.info("准备删除" + str(len(campaign_set)) + "个状态为 pending view 的广告。")
    ntp.control_campaign(campaign_set, campaign_set_cmd)
Ejemplo n.º 3
0
def status_check():
    # 去掉状态为 In Review 且发布时间超过4小时的广告
    pending_campaigns = ds.snap_data.pending_campaigns
    disapproved_campaigns = ds.snap_data.disapproved_campaigns
    need_remove_campaigns = []
    need_remove_campaigns_cmd_type = []
    need_remove_ads = []
    if len(pending_campaigns) > 0:
        time_now = datetime.datetime.now(tool.tz).strftime('%Y-%m-%d %H:%M:%S')
        new_date = datetime.datetime.strptime(time_now, '%Y-%m-%d %H:%M:%S')
        ads_time = mongo.get_campaigns_create_time(pending_campaigns)
        for record in ads_time:
            old_date = datetime.datetime.strptime(record['create_time'], '%Y-%m-%d %H:%M:%S')
            diff_val = new_date - old_date
            if diff_val.seconds / 3600 + diff_val.days * 24 >= 4:
                need_remove_campaigns.append(record['campaign_id'])
                need_remove_campaigns_cmd_type.append('DELETED')
                need_remove_ads.append(record['ad_id'])
    if len(need_remove_campaigns) > 0:
        ntp.control_campaign(need_remove_campaigns, cmd_type=need_remove_campaigns_cmd_type)
        mongo.remove_ads(need_remove_ads)
        log.logger.info(" remove "+str(len(need_remove_campaigns)) +
                        " campaigns for staying In Review status over 4 hours.")
    pending_campaigns_count = len(pending_campaigns) - len(need_remove_campaigns)
    # 发现状态为 Not Approved 的广告触发报警机制
    if len(disapproved_campaigns) > 0:
        message = "discover " + str(len(disapproved_campaigns)) + " ads Not Approved. from : " + os.environ["name"]
        try:
            sms_service.gsm_message(message)
            log.logger.info(message)
        except Exception as e:
            log.logger.info(str(e))
            log.log_exp()
    return pending_campaigns_count, len(need_remove_campaigns)
Ejemplo n.º 4
0
def change_to_active(ads_dict):
    ready_campaigns = list()
    ready_cmd_types = list()
    for ad_id in ads_dict:
        ready_campaigns.append(ads_dict[ad_id])
        ready_cmd_types.append('ACTIVE')
    if len(ready_campaigns) > 0:
        ntp.control_campaign(ready_campaigns, ready_cmd_types)
Ejemplo n.º 5
0
def delete_ads_custom(sub_name, status):
    for name in sub_name:
        campaign_set = get_campaigns_custom(name, status)
        campaign_set_cmd = list()
        for i in range(0, len(campaign_set)):
            campaign_set_cmd.append("DELETED")
        log.logger.info("准备删除" + str(len(campaign_set)) + "个 ads custom 的广告。")
        ntp.control_campaign(campaign_set, campaign_set_cmd)
Ejemplo n.º 6
0
def stop_campaign_process(stop_campaigns, cmd_list):
    start = 0
    step = 100
    end = step
    n_len = len(stop_campaigns)
    if end <= n_len:
        while True:
            ntp.control_campaign(stop_campaigns[start:end], cmd_type=cmd_list[start:end])
            time.sleep(30)
            start = end
            end = start + step
            if end > n_len:
                end = n_len
            if start >= end:
                break
    else:
        ntp.control_campaign(stop_campaigns, cmd_type=cmd_list)

    if n_len > 0:
        log.logger.info("stop " + str(n_len) + " campaigns ...... finished!")