python - 如何让 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)
解决方案
推荐阅读
- c - 执行重定向到哪个文件描述符?
- python - 当我定义它时没有定义变量?
- java - 如何使用 Android 连接到内部存储中的 sqlite 数据库文件?
- c++ - 单击 QFrame 时出现段错误
- reactjs - 为网站上的每个视频链接创建 Opengraph 元标记?
- tensorflow - 使用多个 GPU 时的 TF Keras NAN 损失
- bash - 忽略 GitLab CI 管道脚本中的某些退出代码
- javascript - Discord.js TypeError:无法读取未定义的属性“电子邮件”
- python - 无法解决 ModuleNotFoundError:没有名为“sympy”的模块
- javascript - 在本机脚本 Angular 中接收来自模态的两个回调