# python -m pip install --upgrade pip -i http://pypi.douban.com/simple/ # pip install pymysql -i http://pypi.douban.com/simple/ import datetime import json from MySQLHelper import MySQLHelper # 黄海定义的输出信息的办法,带当前时间 def logInfo(msg): i = datetime.datetime.now() print(" %s %s" % (i, msg)) if __name__ == '__main__': with open("./pack.json", "r", encoding="utf-8") as f: _dict = json.load(f) db = MySQLHelper() for _bean in _dict: # min,max sql = "select min(_id_int) as mi,max(_id_int) as mx from %s" % _bean list = db.query(sql) mi = list[0]['mi'] mx = list[0]['mx'] for action in _dict[_bean]: memo = action["memo"] sql = action["sql"] start = mi while start < mx: _sql = sql + " and t1._id_int >=%s and t1._id_int <%s" % (start, start + 1000) cnt = db.execute(_sql) if cnt > 0: logInfo(memo + ",更新%s条,号段%s~%s" % (cnt, start, start + 1000)) else: logInfo(memo + ",这个,我在空跑!号段%s~%s" % (start, start + 1000)) start = start + 1000 db.close() logInfo("恭喜,所有清洗工作成功完成!")