Client Object

Published on Aug. 19, 2019, 6:31 a.m.

This object is basically the instance of the user which is authenticated using the credentials, and which has an access to the Twitter API.

class TwitterClientObj:
	def __init__(self, twitter_user_id=None):
		"""
		twitter_user_id=None defaults to our user id
		"""
		self.auth = TwitterAuthenticaterObj().authenticate_twitter_app()
		self.twitter_client = API(self.auth)
		self.twitter_user_id = twitter_user_id

	def get_twitter_client_api(self):
		return self.twitter_client

	def get_user_timeline_tweets(self, num_tweets):
		"""
		Extracts the tweets that were tweeted by the user himself
		"""
		user_tweets = []
		for tweet in Cursor(self.twitter_client.user_timeline, id=self.twitter_user_id).items(num_tweets):
			user_tweets.append(tweet)
		return user_tweets

	def get_user_friend_list(self, num_friends):
		"""
		Extracts the friends of a twitter user
		"""
		friend_list = []
		for friend in Cursor(self.twitter_client.friends, id=self.twitter_user_id).items(num_friends):
			friend_list.append(friend)
		return friend_list

	def get_home_timeline_tweets(self, num_tweets):
		""""
		Extracts the home timeline tweets (the tweets that were tweeted by users' followees) of the user 
		"""
		home_timeline_tweets = []
		for tweet in Cursor(self.twitter_client.home_timeline, id=self.twitter_user_id).items(num_tweets):
			home_timeline_tweets.append(tweet)
		return home_timeline_tweets
  • Client Object
    (currently viewing)