odl_ad_tv_lib.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env python
  2. #coding=utf-8
  3. """odl.ad_tv_lib表数据导入
  4. 从yxb.ad_tv_lib提取数据插入到odl.ad_tv_lib表中,作为数据分析来源数据
  5. """
  6. import sys
  7. from fty_util.common import Mysql
  8. reload(sys)
  9. sys.setdefaultencoding('utf8')
  10. conn = Mysql.createOfflineConn()
  11. # 情况odl.ad_tv_lib表数据
  12. # sql = """
  13. # truncate table odl.ad_tv_lib
  14. # """
  15. # Mysql.execute(sql, conn=conn)
  16. # 电视剧信息表
  17. sql = """
  18. replace into odl.ad_tv_lib (tv_id, tv_name, director, scriptwriter, main_actors, types, first_type, second_type, description, \
  19. pub_comp, pub_date, filmer, scheming, producer, produce_comp, produce_date, show_time, is_use, decade, theme) \
  20. select id, tv_name, director, scriptwritter, main_actors, types, \
  21. case when decade is not null and first_type is not null then concat(decade, first_type) else null end as first_type, second_type, \
  22. description, pub_comp, pub_date, production, \
  23. cehua, jianzhi, chupin_comp, chupin_date, show_time, is_use, decade, first_type from yxb.ad_tv_lib
  24. """
  25. Mysql.execute(sql, conn=conn)
  26. # # 更新字段
  27. # sql = """
  28. # update odl.ad_tv_lib set first_type = substring_index(replace(first_type, ' ', ','), ',', 1) where first_type is not null
  29. # """
  30. # Mysql.execute(sql, conn=conn)
  31. # # 清空odl.ad_tv_lib_filter表数据
  32. # sql = """
  33. # truncate table odl.ad_tv_lib_filter
  34. # """
  35. # Mysql.execute(sql, conn=conn)
  36. # # 插入不需要过滤的电视剧
  37. # sql = """
  38. # insert into odl.ad_tv_lib_filter (tv_id, tv_name) \
  39. # select distinct tv_id, tv_name from odl.ad_television group by tv_id, tv_name
  40. # """
  41. # Mysql.execute(sql, conn=conn)
  42. # # 更新odl.ad_tv_lib的is_use字段
  43. # sql = """
  44. # update odl.ad_tv_lib atl inner join odl.ad_tv_lib_filter atlf \
  45. # on atlf.tv_id = atl.id or atlf.tv_name = atl.tv_name
  46. # set atl.is_use = 1
  47. # where atlf.tv_id is not null or atlf.tv_name is not null
  48. # """
  49. # Mysql.execute(sql, conn=conn)
  50. Mysql.close(conn)