#!/usr/bin/env python #coding=utf-8 """ad_television表数据处理 """ import sys from fty_util.common import Mysql reload(sys) sys.setdefaultencoding('utf8') """ """ conn = Mysql.createOfflineConn() # sql = """ # truncate table odl.ad_audience_cps_time # """ # Mysql.execute(sql, conn=conn) # m = 0 # n = 50000 # sql_count = """ # select count(id) from yxb.ad_audience_cps_time # """ # count = 0 # try: # count = Mysql.getOne(sql_count, conn=conn)[0] # except Exception, e: # print e # pass sql = """ select max(tv_date) as max_date from odl.ad_audience_cps_time """ row = Mysql.getOne(sql, conn=conn) max_date = row[0] sql = """ insert into odl.ad_audience_cps_time (id, tv_date, type, area, channel, timebucket, total_num, sex_man, sex_woman, age_414, age_1524, age_2534, age_3544, age_4554, age_5565, age_65, edu_none, edu_primary, edu_middle, edu_high, edu_college, job_manager, job_single, job_civilian, job_worker, job_student, job_none, job_other, inc_2000, inc_2035, inc_3550, inc_5059, inc_5901, inc_none) select id, tv_date, type, area, channel, timebucket, total_num, sex_man, sex_woman, age_414, age_1524, age_2534, age_3544, age_4554, age_5565, age_65, edu_none, edu_primary, edu_middle, edu_high, edu_college, job_manager, job_single, job_civilian, job_worker, job_student, job_none, job_other, inc_2000, inc_2035, inc_3550, inc_5059, inc_5901, inc_none from yxb.ad_audience_cps_time where tv_date > '%s' and timebucket = '全天' and area like 'CSM5%%' """ sql = sql % (max_date) Mysql.execute(sql, conn=conn) Mysql.close(conn)