odl_ad_audience_cps_time.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #!/usr/bin/env python
  2. #coding=utf-8
  3. """ad_television表数据处理
  4. """
  5. import sys
  6. from fty_util.common import Mysql
  7. reload(sys)
  8. sys.setdefaultencoding('utf8')
  9. """
  10. """
  11. conn = Mysql.createOfflineConn()
  12. sql = """
  13. truncate table odl.ad_audience_cps_time
  14. """
  15. Mysql.execute(sql, conn=conn)
  16. m = 0
  17. n = 50000
  18. sql_count = """
  19. select count(id) from yxb.ad_audience_cps_time
  20. """
  21. count = 0
  22. try:
  23. count = Mysql.getOne(sql_count, conn=conn)[0]
  24. except Exception, e:
  25. print e
  26. pass
  27. # 每年数据循环导入
  28. while m <= count + n:
  29. sql = """
  30. insert into odl.ad_audience_cps_time (id, tv_date, type, area, channel, timebucket, total_num, sex_man, sex_woman, age_414,
  31. age_1524, age_2534, age_3544, age_4554, age_5565, age_65, edu_none, edu_primary, edu_middle, edu_high,
  32. 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)
  33. select id, tv_date, type, area, channel, timebucket, total_num, sex_man, sex_woman, age_414,
  34. age_1524, age_2534, age_3544, age_4554, age_5565, age_65, edu_none, edu_primary, edu_middle, edu_high,
  35. 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
  36. from yxb.ad_audience_cps_time
  37. where timebucket = '全天' and area like 'CSM5%%'
  38. limit %s, %s
  39. """
  40. sql = sql % (m, n)
  41. print sql
  42. Mysql.execute(sql, conn=conn)
  43. m += n
  44. Mysql.close(conn)