def randomWalk(userID, MAXHOPS): nodeList = [] nodeSet = set() numRounds = 0 for i in range(MAXHOPS): nodeList.append(userID) nodeSet.add(userID) userList = flickr.contacts_getPublicList(user_id=userID) if(userList): randID = random.randint(1, len(userList)) #get a random number user = userList[randID-1] #get the user indexed by that number try: userID = str(user.id) print randID, userID except: pass else: pass #fix for checking local minima... if ( len(nodeList) - len(nodeSet) > int(MAXHOPS * 0.1) ): print ("nodeList: %s, nodeSet: %s, returning..."%(len(nodeList), len(nodeSet))) print nodeList return print nodeList
def ExploreConnsAndRetData(self, U): if (self.nUsers >= self.nMaxNumOfUsrSupp): exit(0) # Limit exhausted, exit successfully. # Flickr API to retrieve list of Photos with UserID Photos = flickr.people_getPublicPhotos(U.id) if not Photos and not isinstance(U, str): self.log.debug("User: '******' has no photos") else: self.PopulatePhotosAndTags(U, Photos) # Storing the USERID and USERNAME into the database try: if not isinstance(U, str): self.insrtUsr(U.id, U.name) except: pass # Exploring friends' of the user if (self.nUsers < self.nMaxNumOfUsrSupp): FriendsList = flickr.contacts_getPublicList(U.id) if FriendsList: self.PopulateUserConns(U, FriendsList) if (self.Que.qsize() > 0) and (self.nUsers < self.nMaxNumOfUsrSupp): self.ExploreConnsAndRetData(self.Que.get())
def _contacts(self, paused = False): if self._contact_list == None: #if Paused: print(self.id) try: self._contact_list = flickr.contacts_getPublicList(self.id) except: self._contact_list = [] return self._contact_list
def main(MAXROUNDS, rdsConst): userid = "25833004@N07"#zabong nodeList = [] numRounds = 0 ##while (numRound < MAXROUNDS): numRounds += 1 userList = flickr.contacts_getPublicList(user_id=userid) ##print len(userList) userTempList = list(userList) #creating a temp list to randomize lim = (int(0.3 * len(userList))) ##print lim ##print userTempList[:lim ] #for userEntry in userTempList: print userEntry.id nodeList.append(userTempList[:lim ] )
def randomWalk(userID, MAXHOPS): nodeDict = {} nodeList = [] nodeSet = set() numRounds = 0 for i in range(MAXHOPS): #print nodeDict nodeList.append(userID) nodeSet.add(userID) if userID in nodeDict: userList = nodeDict[userID] else: userList = flickr.contacts_getPublicList(user_id=userID) if(isinstance(userList, list)): #making sure the node has contacts #print type(userList), userList, len(userList) #newList = [str(userID.id) for userID in userList] #newList = userList #print newList nodeDict[userID] = userList randID = random.randint(0, len(userList)) #get a random number user = userList[randID-1] #get the user indexed by that number userID = str(user.id) print " -%s"%userID """ try: userID = str(user.id) print randID, userID except: pass """ else: pass #fix for checking local minima... if ( len(nodeList) - len(nodeSet) > int(MAXHOPS * 0.1) ): print ("nodeList: %s, nodeSet: %s, returning..."%(len(nodeList), len(nodeSet))) print nodeList return print nodeList#, nodeDict