Python reddit API:高效解析子reddit中的所有注释

Python reddit API:高效解析子reddit中的所有注释,python,praw,Python,Praw,我试图编写一个聊天机器人,并让它扫描所有添加到它的评论 目前,我通过每X秒扫描一次,直到最后Y条评论: handle = praw.Reddit(username=config.username, password=config.password, client_id=config.client_id, client_secret=config.client_secret,

我试图编写一个聊天机器人,并让它扫描所有添加到它的评论

目前,我通过每X秒扫描一次,直到最后Y条评论:

handle = praw.Reddit(username=config.username,
                    password=config.password,
                    client_id=config.client_id,
                    client_secret=config.client_secret,
                    user_agent="cristiano corrector v0.1a")
while True:
    last_comments = handle.subreddit(subreddit).comments(limit=Y)
    for comment in last_comments:
        #process comments
    time.sleep(X)

我很不满意,因为可能会有很多重叠(这可以通过跟踪评论id来解决),一些评论会被扫描两次,而另一些评论会被忽略。这个API有更好的方法吗?

我在PRAW API中找到了一个利用
流的解决方案。详情见

在我的代码中:

handle = praw.Reddit(username=config.username,
                    password=config.password,
                    client_id=config.client_id,
                    client_secret=config.client_secret,
                    user_agent="cristiano corrector v0.1a")

for comment in handle.subreddit(subreddit).stream.comments():
    #process comments
这将节省一些CPU和网络负载