1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- #!/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
- # 每年数据循环导入
- while m <= count + n:
- 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 timebucket = '全天' and area like 'CSM5%%'
- limit %s, %s
- """
- sql = sql % (m, n)
- print sql
- Mysql.execute(sql, conn=conn)
- m += n
- Mysql.close(conn)
|