def BFS(self, count, random_walk=False): #selfTweets = self._api.user_timeline(user_id=self.id, count=100, include_rts=1) #selfTFIDFArray = getTFIDFArray([t.text for t in selfTweets]) friends = self._api.followers_ids(user_id=self.id)[0] count = min(count, len(friends)) if random_walk: friends = random.sample(friends, count) else: friends = friends[:count] eUsers = [] for frId in friends: try: eUser = EvalUser.loadFromDB(frId) #frTweets = self._api.user_timeline(user_id=frId, count=100, include_rts=1) #frTFIDFArray = getTFIDFArray([t.text for t in frTweets]) if eUser.getSim(self.getTFIDFArray()) > 0.1: eUsers.append(eUser) except Exception, e: handle_exception(e) print "ERROR: ", e pass
def handle_func(func, **args): #if str(args["user_id"])+"\n" in open("not_auths").readlines(): # return [],(0,0) while 1: try: ret = func(**args) return ret except Exception, e: #traceback.print_exc(sys.stderr) handle_exception(e) #time.sleep(3) """ print args print "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE: ",e,sys.argv, args["user_id"] if str(e).find("Not au") != -1 or str(e).find("requires authentication") != -1: open("not_auths", "a").write(str(args["user_id"])+"\n") return [],(0,0) if str(e).find("No such file or ") != -1: l = str(e).split() file = l[-1].replace("'", "").replace(".lock", "") print file os.remove(file) """ raise e
def handle_func(func, **args): #if str(args["user_id"])+"\n" in open("not_auths").readlines(): # return [],(0,0) while 1: try: ret = func(**args) return ret except Exception,e: #traceback.print_exc(sys.stderr) handle_exception(e) #time.sleep(3) """ print args print "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE: ",e,sys.argv, args["user_id"] if str(e).find("Not au") != -1 or str(e).find("requires authentication") != -1: open("not_auths", "a").write(str(args["user_id"])+"\n") return [],(0,0) if str(e).find("No such file or ") != -1: l = str(e).split() file = l[-1].replace("'", "").replace(".lock", "") print file os.remove(file) """ raise e
def BFS(self, count, random_walk=False): #selfTweets = self._api.user_timeline(user_id=self.id, count=100, include_rts=1) #selfTFIDFArray = getTFIDFArray([t.text for t in selfTweets]) friends = self._api.followers_ids(user_id=self.id)[0] count = min(count, len(friends)) if random_walk: friends = random.sample(friends, count) else: friends = friends[:count] eUsers = [] for frId in friends: try: eUser = EvalUser.loadFromDB(frId) #frTweets = self._api.user_timeline(user_id=frId, count=100, include_rts=1) #frTFIDFArray = getTFIDFArray([t.text for t in frTweets]) if eUser.getSim(self.getTFIDFArray()) > 0.1: eUsers.append(eUser) except Exception,e: handle_exception(e) print "ERROR: ",e pass
file = l[-1].replace("'", "").replace(".lock", "") print file os.remove(file) """ raise e if __name__ == "__main__": while 1: try: twitterApi = APISingleton.getInstance() #ids = [random.randint(1, 100000000) for i in range(100)] users = [i.user for i in twitterApi.public_timeline(nocache=True)] friends = users[random.randint(0, len(users))].all_friend_ids() ids = random.sample(friends, min(len(friends), 100)) us = handle_func(twitterApi.lookup_users, user_ids=ids) print len(us) for u in us: EvalUser.load(u) for fId in twitterApi.friends_ids(user_id=u.id)[0]: print "fid: ", fId try: EvalUser.loadFromDB(fId) except Exception, e: handle_exception(e) print e except Exception, e: handle_exception(e) #print traceback.print_exc(sys.stderr) print e
l = str(e).split() file = l[-1].replace("'", "").replace(".lock", "") print file os.remove(file) """ raise e if __name__ == "__main__": while 1: try: twitterApi = APISingleton.getInstance() #ids = [random.randint(1, 100000000) for i in range(100)] users = [i.user for i in twitterApi.public_timeline(nocache=True)] friends = users[random.randint(0, len(users))].all_friend_ids() ids = random.sample(friends, min(len(friends), 100)) us = handle_func(twitterApi.lookup_users, user_ids=ids) print len(us) for u in us: EvalUser.load(u) for fId in twitterApi.friends_ids(user_id=u.id)[0]: print "fid: ",fId try: EvalUser.loadFromDB(fId) except Exception,e: handle_exception(e) print e except Exception, e: handle_exception(e) #print traceback.print_exc(sys.stderr) print e