当前位置: 首页>>代码示例>>Python>>正文


Python API.home_timeline方法代码示例

本文整理汇总了Python中tweepy.API.home_timeline方法的典型用法代码示例。如果您正苦于以下问题:Python API.home_timeline方法的具体用法?Python API.home_timeline怎么用?Python API.home_timeline使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tweepy.API的用法示例。


在下文中一共展示了API.home_timeline方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: TweepyApi

# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import home_timeline [as 别名]
class TweepyApi(BaseTweepyApi, ApiAdapter):
    """
    A `ApiAdapter` implementation using `tweepy` library.

        http://github.com/tweepy/tweepy/
    """

    def __init__(self, *args, **kwargs):
        ApiAdapter.__init__(self, *args, **kwargs)

    # from `turses.api.base.ApiAdapter`

    def init_api(self):
        oauth_handler = TweepyOAuthHandler(self._consumer_key,
                                           self._consumer_secret)
        oauth_handler.set_access_token(self._access_token_key,
                                       self._access_token_secret)
        self._api = BaseTweepyApi(oauth_handler)

    @to_user
    def verify_credentials(self):
        return self._api.me()

    @to_user
    @include_entities
    def get_user(self, screen_name, **kwargs):
        return self._api.get_user(screen_name=screen_name, **kwargs)

    # timelines

    @to_status
    @include_entities
    def get_home_timeline(self, **kwargs):
        tweets = self._api.home_timeline(**kwargs)
        retweets = self._api.retweeted_to_me(**kwargs)
        tweets.extend(retweets)
        return tweets

    @to_status
    @include_entities
    def get_user_timeline(self, screen_name, **kwargs):
        return self._api.user_timeline(screen_name, **kwargs)

    @to_status
    @include_entities
    def get_own_timeline(self, **kwargs):
        me = self.verify_credentials()
        tweets = self._api.user_timeline(screen_name=me.screen_name,
                                         **kwargs)
        retweets = self._api.retweeted_by_me(**kwargs)
        tweets.extend(retweets)
        return tweets

    @to_status
    @include_entities
    def get_mentions(self, **kwargs):
        return self._api.mentions(**kwargs)

    @to_status
    @include_entities
    def get_favorites(self, **kwargs):
        return self._api.favorites(**kwargs)

    @to_direct_message
    @include_entities
    def get_direct_messages(self, **kwargs):
        dms = self._api.direct_messages(**kwargs)
        sent = self._api.sent_direct_messages(**kwargs)
        dms.extend(sent)
        return dms

    # NOTE:
    #  `get_thread` is not decorated with `to_status` because
    #  it uses `TweepyApi.get_user_timeline` which is already
    #  decorated
    @include_entities
    def get_thread(self, status, **kwargs):
        """
        Get the conversation to which `status` belongs.

        It filters the last tweets by the participanting users and
        based on mentions to each other.
        """
        author = status.authors_username
        mentioned = status.mentioned_usernames
        if author not in mentioned:
            mentioned.append(author)

        tweets = []
        for username in mentioned:
            tweets.extend(self.get_user_timeline(username, **kwargs))

        def belongs_to_conversation(status):
            for username in mentioned:
                if username in status.text:
                    return True

        return filter(belongs_to_conversation, tweets)

    @to_status_from_search
#.........这里部分代码省略.........
开发者ID:tazjel,项目名称:turses,代码行数:103,代码来源:backends.py

示例2: start

# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import home_timeline [as 别名]
def start():


	# setup Twitter API connection details
	twitter_auth = OAuthHandler( TWITTER_CONSUMER_KEY, TWITTER_CONSUMER_SECRET )
	twitter_auth.set_access_token( TWITTER_ACCESS_TOKEN, TWITTER_ACCESS_TOKEN_SECRET )

	tweet_api = API(twitter_auth)

	public_tweets = tweet_api.home_timeline(count = 1) #count=1 to read only one tweet

	for tweet in public_tweets:

		print ('{}'.format(tweet))
开发者ID:ChidozieMgbemena,项目名称:CaptureTweet,代码行数:16,代码来源:tweet_home_timeline.py

示例3: __init__

# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import home_timeline [as 别名]
    def __init__(self):
    
		auth = OAuthHandler(app.config['CONSUMER_KEY'], app.config['CONSUMER_SECRET'])
		auth.set_access_token(app.config['ACCESS_TOKEN'], app.config['ACCESS_TOKEN_SECRET'])
		api = API(auth,wait_on_rate_limit=True) 		
		self.db = 'tweets.sqlite'
		self.tweets = []
		#Get worldwide trend topics
		k = api.trends_place(1)
		trends = [i['name'] for i in k[0]['trends']]
		#random_numbers = sample(xrange(len(trends)-1),10) # create 10 random numbers for random trends search
		""" This is the my home_timeline and I'll categorize from my twitter account to more true result """ 
		for tweet in api.home_timeline(count=200, include_rts=0): 
			try:
				url = tweet.entities['urls'][0]['expanded_url']
			except IndexError:
				url = False
			if (url is not False):
				self.tweets.append((
				        tweet.id_str,
				        self.extract_urls(tweet.text),
				        url,
				        str(tweet.created_at).replace(' ', 'T'),
				        tweet.retweet_count,
				        tweet.user.screen_name,
				        tweet.user.profile_image_url.replace("_normal",""),
				        tweet.user.followers_count
				        ))

		for i in range(30):
			for tweet in Cursor(api.search,q=trends[i],result_type="popular").items(19):
				try:
				    url = tweet.entities['urls'][0]['expanded_url']
				except:
				    url = False

				if (url is not False):
				    self.tweets.append((
				            tweet.id_str,
				            self.extract_urls(tweet.text),
				            url,
				            str(tweet.created_at).replace(' ', 'T'),
				            tweet.retweet_count,
				            tweet.user.screen_name,
				            tweet.user.profile_image_url.replace("_normal",""),
				            tweet.user.followers_count
				            ))                                   
开发者ID:yasintoy,项目名称:feedAsistant,代码行数:49,代码来源:storeTweets.py

示例4: NotifyIfCachedResultTests

# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import home_timeline [as 别名]
class NotifyIfCachedResultTests(unittest.TestCase):

    def setUp(self):
        auth = OAuthHandler(oauth_consumer_key, oauth_consumer_secret)
        auth.set_access_token(oauth_token, oauth_token_secret)
        self.api = API(auth)
        self.api.retry_count = 2
        self.api.retry_delay = 5

        if not os.path.exists('cache_test_dir'):
            os.mkdir('cache_test_dir')

        self.api.cache = FileCache('cache_test_dir')
        self.api.cache.flush()

    def testhometimeline_cache(self):
        
        # no calls made, shouldnt be cached
        self.assertEqual(self.api.is_cached_result, False)

        # shouldnt be cached because we just set the cache
        self.api.home_timeline()
        self.assertEqual(self.api.is_cached_result, False)

        # Now should read from cache
        self.api.home_timeline()
        self.assertEqual(self.api.is_cached_result, True)

        # Now shouldnt read from cache, new api method call
        self.api.user_timeline('twitter')
        self.assertEqual(self.api.is_cached_result, False)

        # Now should read from cache, just made api method call
        self.api.user_timeline('twitter')
        self.assertEqual(self.api.is_cached_result, True)

        # Should still read from cache
        self.api.home_timeline()
        self.assertEqual(self.api.is_cached_result, True)
开发者ID:jsh2134,项目名称:tweepy,代码行数:41,代码来源:test_api.py

示例5: TweepyApi

# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import home_timeline [as 别名]
class TweepyApi(BaseTweepyApi, ApiAdapter):
    """
    A :class:`turses.api.ApiAdapter` implementation using `tweepy` library.

        http://github.com/tweepy/tweepy/
    """

    def __init__(self, *args, **kwargs):
        ApiAdapter.__init__(self, *args, **kwargs)

    # from `turses.api.base.ApiAdapter`

    def init_api(self):
        oauth_handler = TweepyOAuthHandler(self._consumer_key,
                                           self._consumer_secret,
                                           secure=configuration.twitter['use_https'])
        oauth_handler.set_access_token(self._access_token_key,
                                       self._access_token_secret)
        self._api = BaseTweepyApi(oauth_handler, secure=configuration.twitter['use_https'])

    @to_user
    def verify_credentials(self):
        return self._api.me()

    @to_user
    @include_entities
    def get_user(self, screen_name, **kwargs):
        return self._api.get_user(screen_name=screen_name, **kwargs)

    # timelines

    @to_status
    @include_entities
    def get_status(self, status_id, **kwargs):
        return self._api.get_status(status_id, **kwargs)

    @to_status
    @include_entities
    def get_home_timeline(self, **kwargs):
        tweets = self._api.home_timeline(**kwargs)
        retweets = self._api.retweeted_to_me(**kwargs)
        tweets.extend(retweets)
        return tweets

    @to_status
    @include_entities
    def get_user_timeline(self, screen_name, **kwargs):
        return self._api.user_timeline(screen_name, **kwargs)

    @to_status
    @include_entities
    def get_own_timeline(self, **kwargs):
        me = self.verify_credentials()
        tweets = self._api.user_timeline(screen_name=me.screen_name,
                                         **kwargs)
        retweets = self._api.retweeted_by_me(**kwargs)
        tweets.extend(retweets)
        return tweets

    @to_status
    @include_entities
    def get_mentions(self, **kwargs):
        return self._api.mentions(**kwargs)

    @to_status
    @include_entities
    def get_favorites(self, **kwargs):
        return self._api.favorites(**kwargs)

    @to_direct_message
    @include_entities
    def get_direct_messages(self, **kwargs):
        dms = self._api.direct_messages(**kwargs)
        sent = self._api.sent_direct_messages(**kwargs)
        dms.extend(sent)
        return dms

    @include_entities
    def get_thread(self, status, **kwargs):
        """
        Get the conversation to which `status` belongs.
        """
        users_in_conversation = [status.authors_username]

        # Save the users that are mentioned
        for user in status.mentioned_usernames:
            if user not in users_in_conversation:
                users_in_conversation.append(user)

        # Fetch the tweets from participants before and after `status`
        # was published
        tweets_from_participants = []
        for user in users_in_conversation:
            user_tweets = self._get_older_and_newer_tweets(user, status.id)
            tweets_from_participants.extend(user_tweets)

        def belongs_to_conversation(tweet):
            for user in users_in_conversation:
                if user in tweet.text:
                    return True
#.........这里部分代码省略.........
开发者ID:floppym,项目名称:turses,代码行数:103,代码来源:backends.py

示例6: TweepyAPITests

# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import home_timeline [as 别名]
class TweepyAPITests(unittest.TestCase):

    def setUp(self):
        auth = OAuthHandler(oauth_consumer_key, oauth_consumer_secret)
        auth.set_access_token(oauth_token, oauth_token_secret)
        self.api = API(auth)
        self.api.retry_count = 2
        self.api.retry_delay = 5

    def testhometimeline(self):
        self.api.home_timeline()

    def testfriendstimeline(self):
        self.api.friends_timeline()

    def testusertimeline(self):
        self.api.user_timeline()
        self.api.user_timeline('twitter')

    def testmentions(self):
        self.api.mentions()

    def testretweetedbyme(self):
        self.api.retweeted_by_me()

    def testretweetedbyuser(self):
        self.api.retweeted_by_user('twitter')

    def testretweetedtome(self):
        self.api.retweeted_to_me()

    def testretweetsofme(self):
        self.api.retweets_of_me()

    def testretweet(self):
        s = self.api.retweet(test_tweet_id)
        s.destroy()

    def testretweets(self):
        self.api.retweets(test_tweet_id)

    def testgetstatus(self):
        self.api.get_status(id=test_tweet_id)

    def testupdateanddestroystatus(self):
        # test update
        text = 'testing %i' % random.randint(0, 1000)
        update = self.api.update_status(status=text)
        self.assertEqual(update.text, text)

        # test destroy
        deleted = self.api.destroy_status(id=update.id)
        self.assertEqual(deleted.id, update.id)

    def testgetuser(self):
        u = self.api.get_user('twitter')
        self.assertEqual(u.screen_name, 'twitter')

        u = self.api.get_user(783214)
        self.assertEqual(u.screen_name, 'twitter')

    def testsearchusers(self):
        self.api.search_users('twitter')

    def testme(self):
        me = self.api.me()
        self.assertEqual(me.screen_name, username)

    def testfriends(self):
        self.api.friends()

    def testfollowers(self):
        self.api.followers()

    def testdirectmessages(self):
        self.api.direct_messages()

    def testsentdirectmessages(self):
        self.api.sent_direct_messages()

    def testsendanddestroydirectmessage(self):
        # send
        sent_dm = self.api.send_direct_message(username, text='test message')
        self.assertEqual(sent_dm.text, 'test message')
        self.assertEqual(sent_dm.sender.screen_name, username)
        self.assertEqual(sent_dm.recipient.screen_name, username)

        # destroy
        destroyed_dm = self.api.destroy_direct_message(sent_dm.id)
        self.assertEqual(destroyed_dm.text, sent_dm.text)
        self.assertEqual(destroyed_dm.id, sent_dm.id)
        self.assertEqual(destroyed_dm.sender.screen_name, username)
        self.assertEqual(destroyed_dm.recipient.screen_name, username)

    def testcreatedestroyfriendship(self):
        enemy = self.api.destroy_friendship('twitter')
        self.assertEqual(enemy.screen_name, 'twitter')

        # Wait 5 seconds to allow Twitter time
        # to process the friendship destroy request.
#.........这里部分代码省略.........
开发者ID:Kudo,项目名称:tweepy,代码行数:103,代码来源:tests.py

示例7: TweepyApi

# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import home_timeline [as 别名]

#.........这里部分代码省略.........
                'created_at': created_at,
                'name': l.name,
                'description': l.description,
                'member_count': l.member_count,
                'subscriber_count': l.subscriber_count,
                'private': private,
            }
            return List(**kwargs)

        if isinstance(lists, list):
            return [to_list(l) for l in lists]
        else:
            return to_list(lists)

    # from `turses.api.base.Api`

    def init_api(self):
        oauth_handler = TweepyOAuthHandler(self._consumer_key,
                                           self._consumer_secret)
        oauth_handler.set_access_token(self._access_token_key,
                                       self._access_token_secret)
        self._api = BaseTweepyApi(oauth_handler)

    def verify_credentials(self):
        def to_user(user):
            kwargs = {
                'screen_name': user.screen_name,
            }
            return User(**kwargs)
        return to_user(self._api.me())

    # timelines

    def get_home_timeline(self, **kwargs):
        tweets = self._api.home_timeline(**kwargs)
        retweets = self._api.retweeted_to_me(**kwargs)
        tweets.extend(retweets)
        return self._to_status(tweets)

    def get_user_timeline(self, screen_name, **kwargs):
        return self._to_status(self._api.user_timeline(screen_name,
                                                       **kwargs))

    def get_own_timeline(self, **kwargs):
        me = self.verify_credentials()
        tweets = self._api.user_timeline(screen_name=me.screen_name,
                                         **kwargs)
        retweets = self._api.retweeted_by_me(**kwargs)
        tweets.extend(retweets)
        return self._to_status(tweets)

    def get_mentions(self, **kwargs):
        return self._to_status(self._api.mentions(**kwargs))

    def get_favorites(self, **kwargs):
        return self._to_status(self._api.favorites(**kwargs))

    def get_direct_messages(self, **kwargs):
        dms = self._api.direct_messages(**kwargs)
        sent = self._api.sent_direct_messages(**kwargs)
        dms.extend(sent)
        return self._to_direct_message(dms)

    def get_thread(self, status, **kwargs):
        author = get_authors_username(status)
        mentioned = get_mentioned_usernames(status)
开发者ID:apg,项目名称:turses,代码行数:70,代码来源:backends.py

示例8: TweepyAPITests

# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import home_timeline [as 别名]
class TweepyAPITests(unittest.TestCase):
    def setUp(self):
        auths = []
        for consumer_key, consumer_secret, access_key, access_secret in oauth_keys:
            auth = OAuthHandler(consumer_key, consumer_secret)
            auth.set_access_token(access_key, access_secret)
            auths.append(auth)

        self.api = API(auths)
        self.api.retry_count = 2
        self.api.retry_delay = 5

    # TODO: Actually have some sort of better assertion
    def testgetoembed(self):
        data = self.api.get_oembed(test_tweet_id)
        self.assertEqual(data["author_name"], "Twitter")

    def testhometimeline(self):
        self.api.home_timeline()

    def testusertimeline(self):
        self.api.user_timeline()
        self.api.user_timeline("twitter")

    def testmentionstimeline(self):
        self.api.mentions_timeline()

    def testretweetsofme(self):
        self.api.retweets_of_me()

    def testretweet(self):
        # TODO(josh): Need a way to get random tweets to retweet.
        raise SkipTest()

    def testretweets(self):
        self.api.retweets(test_tweet_id)

    def testgetstatus(self):
        self.api.get_status(id=test_tweet_id)

    def testupdateanddestroystatus(self):
        # test update
        text = "testing %i" % random.randint(0, 1000)
        update = self.api.update_status(status=text)
        self.assertEqual(update.text, text)

        # test destroy
        deleted = self.api.destroy_status(id=update.id)
        self.assertEqual(deleted.id, update.id)

    def testgetuser(self):
        u = self.api.get_user("twitter")
        self.assertEqual(u.screen_name, "twitter")

        u = self.api.get_user(783214)
        self.assertEqual(u.screen_name, "twitter")

    def testsearchusers(self):
        self.api.search_users("twitter")

    def testsuggestedcategories(self):
        self.api.suggested_categories()

    def testsuggestedusers(self):
        categories = self.api.suggested_categories()
        if len(categories) != 0:
            self.api.suggested_users(categories[0].slug)

    def testsuggesteduserstweets(self):
        categories = self.api.suggested_categories()
        if len(categories) != 0:
            self.api.suggested_users_tweets(categories[0].slug)

    def testme(self):
        me = self.api.me()
        self.assertEqual(me.screen_name, username)

    def testdirectmessages(self):
        self.api.direct_messages()

    def testsentdirectmessages(self):
        self.api.sent_direct_messages()

    def testsendanddestroydirectmessage(self):
        # send
        sent_dm = self.api.send_direct_message(username, text="test message")
        self.assertEqual(sent_dm.text, "test message")
        self.assertEqual(sent_dm.sender.screen_name, username)
        self.assertEqual(sent_dm.recipient.screen_name, username)

        # destroy
        destroyed_dm = self.api.destroy_direct_message(sent_dm.id)
        self.assertEqual(destroyed_dm.text, sent_dm.text)
        self.assertEqual(destroyed_dm.id, sent_dm.id)
        self.assertEqual(destroyed_dm.sender.screen_name, username)
        self.assertEqual(destroyed_dm.recipient.screen_name, username)

    def testcreatedestroyfriendship(self):
        enemy = self.api.destroy_friendship("twitter")
        self.assertEqual(enemy.screen_name, "twitter")
#.........这里部分代码省略.........
开发者ID:QiaozhiWang,项目名称:tweepy,代码行数:103,代码来源:tests.py


注:本文中的tweepy.API.home_timeline方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。