odl_ad_audience_cps_time_incr_update.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. sql = """
  28. select max(tv_date) as max_date from odl.ad_audience_cps_time
  29. """
  30. row = Mysql.getOne(sql, conn=conn)
  31. max_date = row[0]
  32. sql = """
  33. insert into odl.ad_audience_cps_time (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. select id, tv_date, type, area, channel, timebucket, total_num, sex_man, sex_woman, age_414,
  37. age_1524, age_2534, age_3544, age_4554, age_5565, age_65, edu_none, edu_primary, edu_middle, edu_high,
  38. 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
  39. from yxb.ad_audience_cps_time
  40. where tv_date > '%s' and timebucket = '全天' and area like 'CSM5%%'
  41. """
  42. sql = sql % (max_date)
  43. Mysql.execute(sql, conn=conn)
  44. Mysql.close(conn)