#!/usr/bin/env python #coding=utf-8 """更新表odl.ad_tv_record_distribution表的theme, first_type, second_type字段,去除空白符 """ import datetime import os import sys import time from fty_util.common import Mysql reload(sys) sys.setdefaultencoding('utf8') conn = Mysql.createOfflineConn() # 清空走势数据 sql = """ select id, theme, first_type, second_type from odl.ad_tv_record_distribution where LENGTH(theme) > 12 """ rows = Mysql.getAll(sql, conn=conn) for row in rows: _id = row['id'] theme = row['theme'] first_type = row['first_type'] second_type = row['second_type'] theme = theme.replace(' ', '').replace('\r', '').replace('\n', '').replace('\t', '') first_type = first_type.replace(' ', '').replace('\r', '').replace('\n', '').replace('\t', '') second_type = second_type.replace(' ', '').replace('\r', '').replace('\n', '').replace('\t', '') sql = """ update odl.ad_tv_record_distribution set theme = '%s', first_type = '%s', second_type = '%s' where id = '%s' """ sql = sql % (theme, first_type, second_type, _id) Mysql.execute(sql, conn=conn) Mysql.close(conn)