本文介绍了您可以流式传输已成为“热门"的帖子吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我想从 subreddit 的新闻"中流式传输帖子.然而,帖子非常频繁,我们不能说每个帖子都值得.所以我想通过尝试流式传输热门"列表来过滤好帖子.但我不确定这是否可能,或者类似的事情是否可能.
通常,这就是我为流式传输帖子所做的:
在 subreddit.stream.submissions() 中提交:如果不是submission.stickied:打印(str(submission.title) + " " + str(submission.url) + "\n")

So let's say that I want to stream posts from the subreddit "news". However the posts are very frequent and we can't say that every post is worthy. So I would like to filter the good posts by trying to stream the "hot" list. But I am not sure if that, or a similar thing is possible.
Normally, this is what I do to stream posts:
for submission in subreddit.stream.submissions(): if not submission.stickied: print(str(submission.title) + " " + str(submission.url) + "\n")

这将过滤帖子,但不会流式传输:

And this would filter the posts, but not stream it:

在subreddit.hot(limit=10)中提交:打印(str(submission.title) + " " + str(submission.url) + "\n")

那么,关于如何同时流式传输和过滤帖子有什么想法吗?
谢谢

So, any ideas about how I could stream and filter posts at the same time?
Thanks

推荐答案

流式传输热门帖子是一个不协调的想法.

Streaming hot posts is an incongruous idea.

PRAW 中的流的要点是在将每个帖子或评论(几乎)提交到 Reddit 后立即获取.另一方面,热门列表包含被认为当前感兴趣的项目,按分数排序,分数与年龄除以分数成正比.

The point of a stream in PRAW is to get each post or comment (almost) immediately after it is submitted to Reddit. The hot listing, on the other hand, contains the items which are deemed to be currently interesting, ordered by a score which is somewhat proportional to points divided by age.

但是帖子非常频繁,我们不能说每个帖子都值得.

因为 Reddit 用户看到帖子并对其进行投票需要时间,所以在帖子发布后立即评估帖子是否值得(以分数衡量)并没有多大意义.

Because it takes time for Reddit users to see posts and vote on them, it doesn't make much sense to evaluate whether a post is worthy, as measured by score, immediately after it is posted.

如果您的目标是对进入 subreddit 顶部 n 的每个帖子执行某些操作,您可以每隔一定时间检查首页,对您的任何帖子执行您的操作还没有看到.举个例子:

If your goal is to perform some action on every posts that makes it into the top n of a subreddit, you could check the front page on a certain interval, performing your action for any post you haven't already seen. As an example:

import praw
import time


reddit = praw.Reddit()  # must be edited to properly authenticate
subreddit = reddit.subreddit('news')
seen_submissions = set()

while True:
    for submission in subreddit.hot(limit=10):
        if submission.fullname not in seen_submissions:
            seen_submissions.add(submission.fullname)
            print('{} {}\n'.format(submission.title, submission.url))
    time.sleep(60)  # sleep for a minute (60 seconds)

这篇关于您可以流式传输已成为“热门"的帖子吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-05 10:19
查看更多