我正在制作一个 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/