仅通过用户ID以tweety形式发送推文

时间:2017-10-05 19:23:26

标签: python twitter stream attributes tweepy

虽然此代码确实显示了用户的推文,但即使用户被某人提及,也会显示推文。 简而言之,如何只是按用户显示推文而不是提及而不是转发。

class listener(StreamListener):

    def on_status(self, data):
        try:
            if (not data.retweeted) and ('RT @' not in data.text):

                print(data.text)
                print(data.user.name)
                    #print(data.user.location)
                    #print tweetf
                saveThis=str(time.ctime())+'::'+data.text+'/n'
                saveFile = open('twitDB3.txt','a')
                saveFile.write(saveThis)
                saveFile.write('\n')
                saveFile.close()
                return(True)
        except BaseException, e:
            print 'failed on data,',str(e)
            time.sleep(5)

    def on_error(self, status):
        print status

auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)

twitterStream = Stream(auth, listener())
twitterStream.filter(follow=["87725838498"]);

1 个答案:

答案 0 :(得分:0)

下面的代码会为您提供用户推文。根据你更新kwargs数据

auth = OAuthHandler(ckey, csecret)
auth.set_access_token(atoken, asecret)
api = tweepy.API(auth)
kwargs = {'screen_name': <Username of user>,'include_rts': 0, 'count': <Number of tweets, max:200>}
tweets = api.user_timeline(**kwargs) #tweet object has tweets of user