def get_user_by_id(self, user_id: str) -> User: tweepy_user = self.twitter_api.get_user(user_id=user_id) if tweepy_user is not None: user = User.fromTweepyJSON(tweepy_user._json) return user return None
def get_user_by_screen_name(self, screen_name: str) -> User: tweepy_user = self.twitter_api.get_user(screen_name=screen_name) if tweepy_user is not None: user = User.fromTweepyJSON(tweepy_user._json) return user return None
def get_followers_users_by_user_id(self, user_id: str, num_followers=0) -> List[User]: cursor = Cursor(self.twitter_api.followers, user_id=user_id).items(limit=num_followers) followers_users = [] for follower_user in cursor: follower_user.append(User.fromTweepyJSON(follower_user)) return user_id, followers_users
def get_friends_users_by_user_id(self, user_id: str, num_friends=0) -> Tuple[str, list]: """ @param num_friends: 0 means ALL friends, based on tweepy.Cursor.items() """ try: cursor = Cursor(self.twitter_api.friends, user_id=user_id).items(limit=num_friends) friends_users = [] count = 0 for tweepy_user in cursor: count += 1 log.info("Downloaded user " + str(tweepy_user._json.get("id"))) friends_users.append(User.fromTweepyJSON(tweepy_user._json)) log.info(f"total friends {count}") except Exception as e: log.error("error occurs") return user_id, friends_users