python - 循环 reddit 机器人每 10 分钟检查一次答案

标签 python bots reddit

我正在制作一个 Reddit 机器人,它可以处理某些 Reddit 子版 block 的评论,并回复具有某些关键短语的评论。

我最初没有循环,它工作得很好,但我必须每隔几分钟再次单击运行。我正在 pythonanywhere.com 上使用 PRAW 运行我的 python 脚本。

import praw
import time

SECONDS_PER_MIN = 60
subreddit = reddit.subreddit('memes+dankmemes+comics+funny+pics')
keyphrase = ('Sauce+Sauce?')

def main():
    while True:
        for comment in subreddit.stream.comments():
            if keyphrase in comment.body:
                comment.reply('[Here.](https://www.youtube.com/watch?v=dQw4w9WgXcQ)\n\nI am a bot and this action was performed automatically. Learn more at [https://saucebot.com/](https://www.youtube.com/watch?v=dQw4w9WgXcQ)')
                print('Posted!')
                time.sleep(SECONDS_PER_MIN * 11)

if __name__ == '__main__':
    main()

我希望它每 10 分钟随机响应一个说“酱”的人,但现在它不会响应任何人。

最佳答案

您在 PC 上运行脚本吗?您可以使用任务调度程序来实现这一点,而无需使用 python。只需使用 pyinstaller 将脚本保存为二进制文件即可,然后安排它每十分钟运行一次。

关于python - 循环 reddit 机器人每 10 分钟检查一次答案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58699133/

相关文章:

python - 架构 python 问题

c# - 如何使用机器人框架将对象存储在私有(private)对话数据中 - 状态管理

python - discord.ext.commands.errors.CommandInvokeError : Command raised an exception: AttributeError: 'NoneType' object has no attribute 'qualified_name'

Python 在没有预期的情况下返回数据

python - 括号对 Python 中的 'or' 运算符有什么影响?

python - 名称和值 - Go 与 Python

jquery - 使用 jQuery getJSON 在 Reddit 上获取 url 的分数

node.js - 通过浏览器和 NodeJS 请求访问 Reddit json api 时,其行为有所不同

python - 如何对模型属性进行分组

bots - 如何从聊天框中删除 Powered by Api.ai 标志?