# -*- coding: utf-8 -*-import log_configimport ConfigParserimport pymysqllogger = log_config.getlogger(‘getdataabdupdata‘, ‘getdataabdupdata.log‘)conf = ConfigParser.ConfigParser()conf.read("mysql.conf")user = conf.get("mysql", "user")password = conf.get("mysql", "password")database = conf.get("mysql", "database")host = conf.get("mysql", "host")port = conf.get("mysql", "port") # 设置list变量,listdef start(): list = [] with open(‘notice_id.txt‘, ‘r‘)as file: for one in file: # 取到esID esID = one.split(‘,‘)[0] # 添加到list中 list.append(esID) print list logger.info(str(len(list))) if len(list) >= 1000: logger.info(‘start to update pro_status by es_ID 1000 pieces onetime‘) updatepro_status(list) # 更新数据库方法 list = [] # 清空list continue # 更新数据库,批量更新def updatepro_status(list): conn = pymysql.connect(host=host, port=int(port), user=user, passwd=password, db=database) try: cursor = conn.cursor() sql = ‘update ssb_insight_notice set pro_status = 1 where es_id in (%s)‘%‘,‘.join([‘%s‘]*len(list)) print sql effect_row=cursor.execute(sql, list) conn.commit() logger.info("already into dabatabase %s" % effect_row) finally: conn.close()
start() --------------------------------------------------------------------------------------------------------------------------------------------------mysql.conf
[mysql]user=rootpassword=rootdatabase=lipinghost=localhostport =3306
--------------------------------------------------------------------------------------------------------------------------------------------------
notice_id.txt
1205799084,notice/file/1205799084.PDF;1205798435,notice/file/1205798435.PDF;1205798417,notice/file/1205798417.PDF;1205797671,notice/file/1205797671.PDF;1205798441,notice/file/1205798441.PDF;1205798636,notice/file/1205798636.PDF;1205798358,notice/file/1205798358.PDF;1205797800,notice/file/1205797800.PDF;1205797904,notice/file/1205797904.PDF;1205798273,notice/file/1205798273.PDF;1205798572,notice/file/1205798572.PDF;1205798437,notice/file/1205798437.PDF;1205798541,notice/file/1205798541.PDF;1205797788,notice/file/1205797788.PDF;1205798423,notice/file/1205798423.PDF;1205798161,notice/file/1205798161.PDF;1205797841,notice/file/1205797841.PDF;1205798257,notice/file/1205798257.PDF;1205798584,notice/file/1205798584.PDF;1205797924,notice/file/1205797924.PDF;1205798384,notice/file/1205798384.PDF;1205798558,notice/file/1205798558.PDF;1205797464,notice/file/1205797464.PDF;1205798246,notice/file/1205798246.PDF;1205798259,notice/file/1205798259.PDF;1205797819,notice/file/1205797819.PDF;1205797790,notice/file/1205797790.PDF;1205798427,notice/file/1205798427.PDF;1205797624,notice/file/1205797624.PDF;1205797514,notice/file/1205797514.PDF;1205798108,notice/file/1205798108.PDF;1205798191,notice/file/1205798191.PDF;1205798307,notice/file/1205798307.PDF;1205798410,notice/file/1205798410.PDF;1205798658,notice/file/1205798658.PDF;1205797474,notice/file/1205797474.PDF;1205797738,notice/file/1205797738.PDF;
原文地址:https://www.cnblogs.com/sunmoon1993/p/10383524.html
时间: 2024-10-09 19:24:24