def search(client): nameFilter = bayesFilter("name") descriptionFilter = bayesFilter("description") recentlyUsedList = {} APIUseCount = 0 searchList = [] #加入根节点 准备搜索 root_uid = client.get.account__get_uid() root_info = client.get.users__show(uid=root_uid["uid"]) searchList.append(searchNode(root_info, ())) fileptr = file("../debugInfo/consoleInfo.dat", "w") invalidName = file("../debugInfo/invalidName.dat", "w") validName = file("../debugInfo/validName.dat", "w") invalidDescription= file("../debugInfo/invalidDescription.dat", "w") validDescription= file("../debugInfo/validDescription.dat", "w") count = 0; userList = [] idList = set() successFlag = True # 用来记录最近搜索的节点, 如果长期7一个森林里面游荡,强行请出.. recent_search = [] try: while(len(userList) < 5000 and len(searchList)): #Schedule function1 # topNodenum = schedule2(searchList, recentlyUsedList) topNodenum = schedule1(searchList) topNode = searchList[topNodenum] del searchList[topNodenum] recent_search.append(topNode) # debug 信息 count +=1 print "len(searchList): ", len(searchList) s = json.dumps(topNode.getParentList(), encoding="UTF-8", ensure_ascii=False) fileptr.write(str(count) + " "+ topNode.getName() + " " + str(topNode.getValue())+" "+str(topNode.getGradeInfo()) + " " + s.encode("utf-8") + "\n") print str(count) + " "+ topNode.getName() + " " + str(topNode.getValue()) + " " + s.encode("utf-8") # ============================================================================= parentList = topNode.getParentList() #保证只搜索4层之内的东西 if len(parentList) <=3: friends = client.get.friendships__friends(count=200, uid=topNode.getUid()) APIUseCount +=1 print "APIUseCount", APIUseCount topNode.setFriendsList(friends["users"]) for eachitem in friends["users"]: # 满足搜索条件 if searchOrNot(eachitem, idList, nameFilter, descriptionFilter, invalidName, invalidDescription, validName, validDescription): tempList = list(parentList) tempList.append(topNode.getName()) tempNode = searchNode(eachitem, tempList) #evaluate the tempnode value, the bigger, the better tempNode.evaluate() #Insert the node into the search list according to the evaluated value; insertOrderly(searchList,tempNode) insertOrderly(userList,tempNode) idList.add(eachitem["id"]) except Exception as ex: successFlag = False userListptr = file("../debugInfo/UserlistPickle", "w") searchListptr = file("../debugInfo/searchlistPickle", "w") cPickle.dump(userList, userListptr) cPickle.dump(searchList, userListptr) print_searchList(userList, "../debugInfo/userList") print "Error!!!" print "APIUseCount", APIUseCount print "======================================" print ex if successFlag: userListptr = file("../debugInfo/UserlistPickle", "w") cPickle.dump(userList, userListptr) print_searchList(userList, "../debugInfo/userList") print "APIUseCount", APIUseCount
def __init__(self): self.commmentFilter = bayesFilter("comment") self.validfileptr = file("../debugInfo//validComment", "a") self.invalidfileptr = file("../debugInfo/invalidComment", "a")