首页 > 解决方案 > 如何让 Praw Script 同时观看多个流

问题描述

我有一个 redditbot,如果它收到一条消息,或者某个 subreddit 收到具有特定标题的帖子,它需要采取行动。我不想同时在我的计算机后台运行两个不同的 python 脚本(一个看机器人收件箱,一个看机器人指定 subreddit)。有没有办法将多个流合并为一个?

就像是:

for post, msg in reddit.inbox.strea() or subreddit.posts.stream():
     do msg action
     do post action

这是我试图合并到一个流中的两段代码:

1

for msg in reddit.inbox.stream(skip_existing = True):
    if msg == 'all':
        all_repots()
    else:
        report(msg)

2

subs = reddit.subreddit('SomeSubreddit')


status = str('This is my status!')




for post in subs.stream.submissions():
    if 'botname' and 'report!' in post.title:
        post.reply(status)

标签: pythonpraw

解决方案


推荐阅读