Created
December 19, 2011 05:28
-
-
Save harmy/1495539 to your computer and use it in GitHub Desktop.
将行会数据从文本导入mysql
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# -*- coding: gbk -*- | |
__author__ = 'harmy' | |
import glob | |
def main(): | |
guild_master = {} | |
guild_member_count = {} | |
with open("update_guild.sql", "w+") as f: | |
#插入tbl_guild_member表 | |
for txt_file in glob.glob("*.txt"): | |
guild_name = txt_file[:-4] | |
with open(txt_file, "r") as f1: | |
guild_members = [line[1:][:-3] for line in f1.readlines() if line.startswith("+")] | |
guild_master[guild_name] = guild_members[0] | |
guild_member_count[guild_name] = len(guild_members) | |
for member in guild_members: | |
f.write("insert into tbl_guild_member(guild,username) values('%s', '%s');\n" % (guild_name, member)) | |
#插入tbl_guild表 | |
for ini_file in glob.glob("*.ini"): | |
guild_name = ini_file[:-4] | |
f.write("insert into tbl_guild(name,maxcount) values('%s',50);\n" % guild_name) | |
f.write("update tbl_guild set master = '%s', count=%d where name = '%s';\n" % (guild_master[guild_name], guild_member_count[guild_name], guild_name)) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment