A method for combining streams
See original GitHub issueOne of the most common issues I see in new developers when they are trying to write a reddit bot is that they can’t figure out how to stream more than one thing. The two recommended solutions of either breaking after a certain number of requests to check the other stream, or using multiple processes are unintuitive and often end up causing the developer more problems than they solve.
An approach like this
subreddit = reddit.subreddit("redditdev")
for item in praw.models.util.stream_generator([subreddit.comments, subreddit.new]):
if item.fullname.startswith("t3_"):
print("New submission")
elif item.fullname.startswith("t1_"):
print("New comment")
would be much easier to use. It would require multiple api calls to fetch a new batch, but users would already be doing that anyway if they were using multiple streams, and streams generally don’t get any new items on the vast majority of their calls, so it’s unlikely to even be noticed.
It would require somewhat significantly reworking how streams work. It would need to store a before parameter per function, and the arguments attribute_name
and exclude_before
would need to be passed in differently. It would also need to fetch all the items for the streams and manually sort them to return them in the correct order.
It might be simpler to rework streams into their own class, similar to the proposal in #1025
Issue Analytics
- State:
- Created 3 years ago
- Comments:10 (8 by maintainers)
Top GitHub Comments
@LilSpazJoekp and @Watchful1 , thanks for the feedback.
This issue was closed because it has been stale for 10 days with no activity.