build_wid.py
This commit is contained in:
parent
442693556a
commit
25ecad6581
117
scripts/build_wid/build_wid.py
Normal file
117
scripts/build_wid/build_wid.py
Normal file
@ -0,0 +1,117 @@
|
|||||||
|
import pymysql
|
||||||
|
import hashlib
|
||||||
|
|
||||||
|
print('runing........')
|
||||||
|
|
||||||
|
host_name = "127.0.0.1"
|
||||||
|
user_name = "root"
|
||||||
|
password = "keji178"
|
||||||
|
database_name= "accountdb" + "1"
|
||||||
|
table_name = "accounts"
|
||||||
|
|
||||||
|
|
||||||
|
database_config = {
|
||||||
|
'host_name' : host_name,
|
||||||
|
'user_name' : user_name,
|
||||||
|
'password' : password,
|
||||||
|
'database_name' : database_name
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
select_config = [
|
||||||
|
'country',
|
||||||
|
'province',
|
||||||
|
'city',
|
||||||
|
'sex',
|
||||||
|
'nickname',
|
||||||
|
'idx',
|
||||||
|
'accountid'
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
|
def getDatabaseCursor(config):
|
||||||
|
#print('getDatabaseCursor\n')
|
||||||
|
|
||||||
|
db = pymysql.connect(config['host_name'],config['user_name'],config['password'],config['database_name'])
|
||||||
|
return db.cursor()
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def getSelectInfo(min_idx,max_idx,s_config):
|
||||||
|
#print('getSelectInfo\n')
|
||||||
|
|
||||||
|
try:
|
||||||
|
cursor = getDatabaseCursor(s_config)
|
||||||
|
select_sql = 'select country, province, city, sex, nickname , idx, accountid \
|
||||||
|
from accounts where idx > %s and idx <%s and accountid is not null' % (min_idx,max_idx)
|
||||||
|
cursor.execute(select_sql)
|
||||||
|
ret = cursor.fetchall()
|
||||||
|
except:
|
||||||
|
print('sql error!')
|
||||||
|
return
|
||||||
|
|
||||||
|
return ret
|
||||||
|
|
||||||
|
|
||||||
|
def translateToMd5(translate_info):
|
||||||
|
#print('translateTomd5\n')
|
||||||
|
|
||||||
|
if translate_info:
|
||||||
|
m = hashlib.md5()
|
||||||
|
b = translate_info.encode(encoding = 'utf-8')
|
||||||
|
m.update(b)
|
||||||
|
return m.hexdigest()
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
def saveTofile(save_info,save_name):
|
||||||
|
#print('saveTofile\n')
|
||||||
|
|
||||||
|
if save_info and save_name :
|
||||||
|
with open(save_name,'a') as f:
|
||||||
|
f.write("%s\n"%(save_info))
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
def buildWid():
|
||||||
|
|
||||||
|
select_min_idx = 10000
|
||||||
|
select_max_idx = select_min_idx + 100
|
||||||
|
|
||||||
|
finsh_flag = 1;
|
||||||
|
select_count = 0;
|
||||||
|
save_file_name = 'updata_wid.txt'
|
||||||
|
|
||||||
|
|
||||||
|
while select_count < 100 and finsh_flag:
|
||||||
|
|
||||||
|
min_idx = select_min_idx + select_count * 100
|
||||||
|
max_idx = select_max_idx + select_count * 100
|
||||||
|
|
||||||
|
select_info = getSelectInfo(min_idx,max_idx,database_config)
|
||||||
|
|
||||||
|
if select_info:
|
||||||
|
for player_info in select_info:
|
||||||
|
|
||||||
|
country = player_info[0]
|
||||||
|
province = player_info[1]
|
||||||
|
city = player_info[2]
|
||||||
|
sex = player_info[3]
|
||||||
|
nickname = player_info[4]
|
||||||
|
idx = player_info[5]
|
||||||
|
accountid = player_info[6]
|
||||||
|
|
||||||
|
new_str = '%s%s%s%s%s'%(country, province, city, sex, nickname)
|
||||||
|
md5_str = translateToMd5(new_str)
|
||||||
|
update_sql = "UPDATE %s SET wid = '%s' where accountid = '%s';"%(table_name,md5_str,accountid)
|
||||||
|
saveTofile(update_sql,save_file_name)
|
||||||
|
select_count = select_count + 1
|
||||||
|
else:
|
||||||
|
finsh_flag = 0
|
||||||
|
|
||||||
|
print('buidWid END!')
|
||||||
|
return
|
||||||
|
|
||||||
|
|
||||||
|
buildWid()
|
Loading…
x
Reference in New Issue
Block a user