记录一段python代码 (修改数据库字符串)
发表于:2024-09-21 作者:千家信息网编辑
千家信息网最后更新 2024年09月21日,场景:由于开发恶心的账号登录设置,鉴于日本玩家用户习惯,刚开始以游客的身份登录游戏,若发生换包或者换设备,都需要从数据库重新更换账号ID,刚开始纯手工,其后py实现,封装为exe直接在dos里面执行,
千家信息网最后更新 2024年09月21日记录一段python代码 (修改数据库字符串)
场景:由于开发恶心的账号登录设置,鉴于日本玩家用户习惯,刚开始以游客的身份登录游戏,若发生换包或者换设备,都需要从数据库重新更换账号ID,刚开始纯手工,其后py实现,封装为exe直接在dos里面执行,最好的方式改进当然是在web见面一键完成,现将代码跑路,作为记录。
# coding=utf-8import pymysqlimport tracebackimport simplejsonimport sys# 交换def exchange(connect_index, file_name): try: # 读取数据库配置 fp = open("config.json") connect_info = simplejson.load(fp)["db_list"] fp.close() # 创建链接 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以免发生冲突 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文件 还未整理,若有疑问请问博主,反正他也不会告诉你。
数据
数据库
账号
登录
代码
恶心
两个
光标
场景
手工
文件
方式
是在
最好
游客
玩家
用户
疑问
设备
身份
数据库的安全要保护哪些东西
数据库安全各自的含义是什么
生产安全数据库录入
数据库的安全性及管理
数据库安全策略包含哪些
海淀数据库安全审计系统
建立农村房屋安全信息数据库
易用的数据库客户端支持安全管理
连接数据库失败ssl安全错误
数据库的锁怎样保障安全
数据库代码dw
vba查询数据库出现自动化错误
以下网络安全的认识是错误的
儿童网络安全竞争对手
亳州oa管理软件开发费用
建筑施工网络技术
报表的数据库
妇联开展网络安全宣传简报
电子商务和互联网科技
商品资料库数据库
为什么王者服务器会崩溃
网络安全属于网络层吗
网络安全隔离装置的作用是什么
网络安全手抄报内容照片
软件开发的过程活动
网络安全985硕士专业年薪
网络安全教育班会主题发言稿
信息软件开发学习
网络安全隐患整改的请示
网络安全基层行
网络安全防御系统原理
数据库服务器代理地址
G60网络安全
网络安全边界最小化原则
内蒙古数据软件开发价格
数据库设计文件怎么写
arm服务器应用于什么领域
出现网络安全错误论文
华盛网络技术有限公司
数据库开发工程师招聘