gpt4 book ai didi

python - 如何线程 Tweepy 流

转载 作者:太空宇宙 更新时间:2023-11-04 00:46:44 24 4
gpt4 key购买 nike

我正在制作一个程序,使用 Tweepy 提取实时推文,并通过一个函数运行它。我正在使用 Tweepy Stream 来完成获取推文的任务。然而,我希望的是,在该功能运行时,Tweepy 仍然可以拉取这些实时推文。我相信我需要将 Tweepy 事件监听器线程化,但我不完全确定如何执行此操作。

def doesSomething(s):
#function here

class listener(tweepy.StreamListener):
def on_status(self, status):
doesSomething(status)

stream_listener = listener()
tweepy.Stream(auth = api.auth, listener=stream_listener)
stream.filter(track=["Example"])

最佳答案

您可以使用 async=True 参数在另一个线程中运行流:

myStream.filter(track=['python'], async=True)

参见 http://docs.tweepy.org/en/v3.5.0/streaming_how_to.html获取更多信息。

关于python - 如何线程 Tweepy 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39237420/

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