python分类查询

来源:互联网 发布:淘宝免单群是怎么运作 编辑:程序博客网 时间:2024/05/16 16:11
#!/usr/bin/python#-*- coding: UTF-8 -*-import os, sys, string, codecs# 设置字符集reload(sys)sys.setdefaultencoding("utf-8")# 将比赛ID, 玩家id加入def AddMapKeySetVal(Map, Key, Val):    if Map.has_key(Key):        Map[Key].add(Val)    else:        Map[Key] = set()        Map[Key].add(Val)def RemoveOneVal(Map, Key, Val):    if Map.has_key(Key):        Map[Key].discard(Val)def RemoveKey(Map, Key):    if Map.has_key(Key):        del Map[Key]def PrintMap(file, Map):    count = 0    line = ""    userDic = {};    userList = [];    for (Key, Val) in Map.items():        for userid in Val:            line += "%s\n" % userid            count += 1;            if count%100 == 0:                #print line                file.write(line)                line = ""    file.write(line)# 获取长字符串中,两个字符串中间的值def getValue(srcStr, destStr1, destStr2):    start = srcStr.find(destStr1) + len(destStr1)    end = -1    if destStr2 != "":        end = srcStr.find(destStr2)    return srcStr[start:end]#处理matchserverlogdef handleMatchserverLog(fileName):    matchDic = {}    file = open(fileName)    for line in file:        # 处理用户加入的比赛        if line.find("user join match delcard, cardCount") > -1:            matchId = getValue(line, "matchId:", ", userId:")            userId  = getValue(line, " userId:", "")            AddMapKeySetVal(matchDic,matchId,userId)        if line.find("user quit match addcard, cardCount") > -1:            matchId = getValue(line, " matchId:", ", userId:")            userId = getValue(line, " userId:", "")            RemoveOneVal(matchDic, matchId, userId)        if line.find("FinalRankingInfo matchID") > -1:            matchId = getValue(line, " matchID:", "    Order:")            RemoveKey(matchDic, matchId)    output = open('AddCardUserd_new.txt','a')    PrintMap(output,matchDic)    #print matchDicfileName = "2017-08-10_MatchServer(1).log"handleMatchserverLog(fileName)
原创粉丝点击