有没有办法合并 posts/comment 流?
Is there a way to combine posts/comment streams?
大虾,我可以创建subreddit.stream.comments()
或subreddit.stream.submissions()
。
对于那些不熟悉的人,上面的两个praw功能return comments/posts因为它们进来了。
有没有办法将两者结合起来?我试过使用 Python 的内置函数 zip
以及 itertools
的 zip_longest
,但它们都只在帖子出现时给出结果.(评论 多 更频繁)。
找到答案:
comment_stream = subreddit.stream.comments(pause_after=-1)
submission_stream = subreddit.stream.submissions(pause_after=-1)
while True:
for comment in comment_stream:
if comment is None:
break
print(comment.author)
for submission in submission_stream:
if submission is None:
break
print(submission.title)
关键是pause_after
参数。
大虾,我可以创建subreddit.stream.comments()
或subreddit.stream.submissions()
。
对于那些不熟悉的人,上面的两个praw功能return comments/posts因为它们进来了。
有没有办法将两者结合起来?我试过使用 Python 的内置函数 zip
以及 itertools
的 zip_longest
,但它们都只在帖子出现时给出结果.(评论 多 更频繁)。
找到答案:
comment_stream = subreddit.stream.comments(pause_after=-1)
submission_stream = subreddit.stream.submissions(pause_after=-1)
while True:
for comment in comment_stream:
if comment is None:
break
print(comment.author)
for submission in submission_stream:
if submission is None:
break
print(submission.title)
关键是pause_after
参数。