gpt4 book ai didi

python - Tweepy 在流中回复推文

转载 作者:行者123 更新时间:2023-11-30 22:53:30 25 4
gpt4 key购买 nike

我有一个 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

关于python - Tweepy 在流中回复推文,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38162239/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com