In praw, I can create either a subreddit.stream.comments()
or subreddit.stream.submissions()
.
For those unfamiliar, the two above praw functions return comments/posts as they come in.
Is there a way to combine the two? I've tried using Python's built-in function zip
as well as itertools
's zip_longest
but they both only give a result as fast as the posts come in. (Comments are much more frequent).
Found the answer:
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)
The key is the pause_after
parameter.