簡體   English   中英

Tweety回復推文流

[英]Tweepy reply to tweet in stream

我有一個Twitter機器人響應包含主題標簽的推文。 我一直在使用twt = api.search(q='param')來推送推文並且它一直工作得很好但我已經切換到myStreamListener = MyStreamListener() twt = tweepy.Stream(auth = api.auth, listener=myStreamListener())實時提取推文。 這不行,但我不知道為什么。 這是我的代碼:

myStreamListener = MyStreamListener()
twt = tweepy.Stream(auth = api.auth, listener=myStreamListener())

twt.filter(track=['#www'], async=True)

#list of specific strings we want to omit from responses
badWords = ['xxx','yyy' ]

#list of specific strings I want to check for in tweets and reply to

genericparam = ['@zzz']

def does_contain_words(tweet, wordsToCheck):
    for word in wordsToCheck:
        if word in tweet:
            return True
    return False

for currentTweet in twt:
    #if the tweet contains a good word and doesn't contain a bad word
    if does_contain_words(currentTweet.text, genericparam) and not does_contain_words(currentTweet.text, badWords):
        #reply to tweet
        screen = currentTweet.user.screen_name
        message = "@%s this is a reply" % (screen)
        currentTweet = api.update_status(message, currentTweet.id)

我相信你的問題是你試圖通過流發送回復,而不是在單獨的線程中使用http請求。 如下所述,這是不可能的:

https://dev.twitter.com/streaming/overview

偶然發現了這個。

當您創建myStreamListener = MyStreamListener(self.api) self.api實例時,您需要將需要傳遞給StreamListner構造函數,否則它將為null。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM