#!/usr/bin/env python
# -*- coding: utf-8 -*-
# @Time : 2020/1/15 14:32
# @Author : H
# @File : update_id_all.py
import MySQLdb as mdb
def updateID(tablename,DBname):
"""
Creation Time: 2020/1/15 14:08
Author: H
function: update DBid
arguments: tablename, conn
return:
"""
conn = mdb.connect(host='localhost',
port=3306,
user='root',
passwd='123456',
db = DBname,
charset='utf8')
cur = conn.cursor()
sql = "select * from %s" % (tablename)
cur.execute(sql)
rows = cur.fetchall()
sub = []
for i in rows:
sub.append(i[0])
k = 1
for i in sub:
sql1 = "update %s set id = %s where id =%s" % (tablename, k, i)
print(sql1)
k += 1
cur.execute(sql1)
conn.commit()
conn.close()
if __name__ == '__main__':
tables = {'find_report' : ['crawled_report_table','apt_report_table']}
for k, v in tables.items():
for i in v:
updateID(i, k)