一段时间后重复功能

时间:2020-08-06 03:06:22

标签: python-3.x function python-multithreading

好,这就是事情了:我正在执行这段代码,该代码访问reddit,下载一些内容,然后发布到Twitter上,它的其他部分监视内容流,并等待直到有人说某些关键字可以完成某些事情为止。由于观看部分已经是恒定的,现在我只想让第二部分在一段时间后运行,现在,我正在使用流观察器来触发该功能(也就是,当流观察器从Twitter接收到信号时,它将运行函数),这有点奏效,但并不一致。我见过This link,但由于我对python线程的了解不多,这让我有些困惑。

这是我正在使用的代码:

def buscarreddit():
  *function that searchs on reddit and posts*

api = tweepy.API(auth, wait_on_rate_limit=True,
    wait_on_rate_limit_notify=True)


class MyStreamListener(tweepy.StreamListener):
    def __init__(self, api):
        self.api = api
        self.me = api.me()

    def on_status(self, tweet):
        print(f"{tweet.user.name}:{tweet.text}")
        api.create_favorite(tweet.id)
        frequency = 2500
        duration = 200
        winsound.Beep(frequency, duration)
        buscarreddit()

    def on_error(self, status):
        print("Error detected")

api = tweepy.API(auth)
try:
    api.verify_credentials()
    print("Authentication OK")
except:
    print("Error during authentication")



tweets_listener = MyStreamListener(api)
stream = tweepy.Stream(api.auth, tweets_listener)
stream.filter(track=["trigger"], languages=["en"])

我接受了你们可以给我的建议和/或解释

谢谢。

0 个答案:

没有答案
相关问题