場景:由于開發(fā)惡心的賬號登錄設置,鑒于日本玩家用戶習慣,剛開始以游客的身份登錄游戲,若發(fā)生換包或者換設備,都需要從數(shù)據(jù)庫重新更換賬號ID,剛開始純手工,其后py實現(xiàn),封裝為exe直接在dos里面執(zhí)行,最好的方式改進當然是在web見面一鍵完成,現(xiàn)將代碼跑路,作為記錄。

創(chuàng)新互聯(lián)是一家專注于網(wǎng)站制作、
成都做網(wǎng)站與策劃設計,站前網(wǎng)站建設哪家好?創(chuàng)新互聯(lián)做網(wǎng)站,專注于網(wǎng)站建設十多年,網(wǎng)設計領(lǐng)域的專業(yè)建站公司;建站業(yè)務涵蓋:站前等地區(qū)。站前做網(wǎng)站價格咨詢:13518219792# coding=utf-8
import pymysql
import traceback
import simplejson
import sys
# 交換
def exchange(connect_index, file_name):
try:
# 讀取數(shù)據(jù)庫配置
fp = open("config.json")
connect_info = simplejson.load(fp)["db_list"]
fp.close()
# 創(chuàng)建鏈接
conn = pymysql.connect(host=str(connect_info[connect_index]["ip"]),
port=int(connect_info[connect_index]["port"]),
user=str(connect_info[connect_index]["user"]),
passwd=str(connect_info[connect_index]["passwd"]),
db=str(connect_info[connect_index]["db_name"]),
charset='utf8')
# 獲取光標
cur = conn.cursor()
# 讀取交換列表
fp = open(str(file_name))
exchange_data = simplejson.load(fp)
fp.close()
# 開始交換
for item in exchange_data:
# 讀取兩個值的account_id
player_datas = []
for i in range(2):
temp_data = {}
cur.execute("select `id`, `account_id` from `character` where `"
+ str(item["key"][i])
+ "` = '"
+ str(item["value"][i]) + "'")
result = cur.fetchall()
temp_data["id"] = result[0][0]
temp_data["account_id"] = result[0][1]
player_datas.append(temp_data)
# 更改account_id以免發(fā)生沖突
for player_data in player_datas:
cur.execute("update `character` set `account_id` = '" + str(
player_data["account_id"]) + "_' where `id` = '" + str(player_data["id"]) + "'")
conn.commit()
# 交換
temp_data = player_datas[0]["account_id"]
player_datas[0]["account_id"] = player_datas[1]["account_id"]
player_datas[1]["account_id"] = temp_data
for player_data in player_datas:
cur.execute("update `character` set `account_id` = '" + str(
player_data["account_id"]) + "' where `id` = '" + str(player_data["id"]) + "'")
conn.commit()
conn.close()
except Exception:
traceback.print_exc()
if __name__ == '__main__':
try:
if len(sys.argv) < 3:
print "arg error"
sys.exit(1)
exchange(int(sys.argv[1]), sys.argv[2])
except Exception:
traceback.print_exc()
部分json文件 還未整理,若有疑問請問博主,反正他也不會告訴你。
另外有需要云服務器可以了解下創(chuàng)新互聯(lián)cdcxhl.cn,海內(nèi)外云服務器15元起步,三天無理由+7*72小時售后在線,公司持有idc許可證,提供“云服務器、裸金屬服務器、高防服務器、香港服務器、美國服務器、虛擬主機、免備案服務器”等云主機租用服務以及企業(yè)上云的綜合解決方案,具有“安全穩(wěn)定、簡單易用、服務可用性高、性價比高”等特點與優(yōu)勢,專為企業(yè)上云打造定制,能夠滿足用戶豐富、多元化的應用場景需求。
網(wǎng)站欄目:記錄一段python代碼(修改數(shù)據(jù)庫字符串)-創(chuàng)新互聯(lián)
標題網(wǎng)址:http://www.2m8n56k.cn/article30/dhpcso.html
成都網(wǎng)站建設公司_創(chuàng)新互聯(lián),為您提供微信小程序、搜索引擎優(yōu)化、網(wǎng)站營銷、App設計、企業(yè)建站、面包屑導航
廣告
聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:[email protected]。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源:
創(chuàng)新互聯(lián)