odl_ad_tv_record_distribution_update_theme_field.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. #!/usr/bin/env python
  2. #coding=utf-8
  3. """更新表odl.ad_tv_record_distribution表的theme, first_type, second_type字段,去除空白符
  4. """
  5. import datetime
  6. import os
  7. import sys
  8. import time
  9. from fty_util.common import Mysql
  10. reload(sys)
  11. sys.setdefaultencoding('utf8')
  12. conn = Mysql.createOfflineConn()
  13. # 清空走势数据
  14. sql = """
  15. select id, theme, first_type, second_type from odl.ad_tv_record_distribution where LENGTH(theme) > 12
  16. """
  17. rows = Mysql.getAll(sql, conn=conn)
  18. for row in rows:
  19. _id = row['id']
  20. theme = row['theme']
  21. first_type = row['first_type']
  22. second_type = row['second_type']
  23. theme = theme.replace(' ', '').replace('\r', '').replace('\n', '').replace('\t', '')
  24. first_type = first_type.replace(' ', '').replace('\r', '').replace('\n', '').replace('\t', '')
  25. second_type = second_type.replace(' ', '').replace('\r', '').replace('\n', '').replace('\t', '')
  26. sql = """
  27. update odl.ad_tv_record_distribution set theme = '%s', first_type = '%s', second_type = '%s' where id = '%s'
  28. """
  29. sql = sql % (theme, first_type, second_type, _id)
  30. Mysql.execute(sql, conn=conn)
  31. Mysql.close(conn)