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


Python API.retweets方法代码示例

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


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

示例1: runTest

# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import retweets [as 别名]
def runTest(auth, geocode):
    searchText = "flash mob OR mobs OR flashmob"
    nycGeoCode = "40.714353,-74.00597299999998,20km"

    api = API(auth)

    if geocode is True:
        tweets = api.search(searchText, geocode=nycGeoCode, lang="en", rpp="100")
    else:
        #Note: This may cause a too many requests Twitter error
        tweets = api.search(searchText, lang="en", rpp="100")

    #basically find tweets that match the search criteria
    users_list = []
    i = 0
    for tweet in tweets:
        print(i)
        i = i + 1
        name = tweet.user.name.encode("utf-8", errors='ignore')
        user_id = tweet.user.id #.encode("utf-8", errors='ignore')
        tweet_text = tweet.text.encode("utf-8", errors='ignore')

        #Ignore users we have already checked
        if (users_list.count(name)):
            continue
        else:
            users_list.append(name)

        #Add number of times the user has used the search criteria in the past
        tweet_count = 0
        retweet_count = 0
        users_tweets = api.user_timeline(id=user_id, count="500")
        for users_tweet in users_tweets:
            if (re.search(r'flash[ ]?mob[s]?', users_tweet.text, flags=re.IGNORECASE)):
                tweet_count = tweet_count + 1
                #Check how many times the past tweets have been retweeted
                retweet_count = retweet_count + len(api.retweets(id=users_tweet.id))

        #Checks how many followers this person has
        followers_count = len(api.followers_ids(id=user_id))

        print("User ID:       ", user_id)
        print("Tweet count:   ", tweet_count)
        print("retweet_count: ", retweet_count)
        print()

    return
开发者ID:bzabinski,项目名称:FlashMobPredictor,代码行数:49,代码来源:main.py

示例2: on_data

# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import retweets [as 别名]
    def on_data(self, data):
        print("Found something")
        try:
            decoded = json.loads(data)
        except:
            print("JSON couldn't be loaded")

        name = decoded['user']['name'].encode("utf-8", errors='ignore')
        user_id = decoded['user']['id'] #.encode("utf-8", errors='ignore')
        tweet_text = decoded['text'].encode("utf-8", errors='ignore')

        #Add number of times the user has used the search criteria in the past
        tweet_count = 0
        retweet_count = 0

        try:
            auth = AppAuthHandler(consumer_key, consumer_secret)
            auth.apply_auth()
            api = API(auth)

            users_tweets = api.user_timeline(id=user_id, count="500")
            for users_tweet in users_tweets:
                if (re.search(r'flash[ ]?mob[s]?', users_tweet.text, flags=re.IGNORECASE)):
                    tweet_count = tweet_count + 1
                    #Check how many times the past tweets have been retweeted
                    retweet_count = retweet_count + len(api.retweets(id=users_tweet.id))

            #Checks how many followers this person has
            followers_count = len(api.followers_ids(id=user_id))

        except:
            print("Something went wrong when gathering more data")
            return True

        print("User ID:       ", user_id)
        print("Tweet count:   ", tweet_count)
        print("retweet_count: ", retweet_count)
        print()

        post = {"user_id": user_id,
                "tweet": tweet_text.decode(encoding='utf-8',errors='ignore'),
                "tweet_count": tweet_count,
                "retweet_count": retweet_count}

        posts.insert(post)

        return True
开发者ID:bzabinski,项目名称:FlashMobPredictor,代码行数:49,代码来源:main.py

示例3: TweepyAPITests

# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import retweets [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

示例4: TweepyAPITests

# 需要导入模块: from tweepy import API [as 别名]
# 或者: from tweepy.API import retweets [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.retweets方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。