本文整理汇总了Python中praw.Reddit.get_random_subreddit方法的典型用法代码示例。如果您正苦于以下问题:Python Reddit.get_random_subreddit方法的具体用法?Python Reddit.get_random_subreddit怎么用?Python Reddit.get_random_subreddit使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类praw.Reddit
的用法示例。
在下文中一共展示了Reddit.get_random_subreddit方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: whoosh
# 需要导入模块: from praw import Reddit [as 别名]
# 或者: from praw.Reddit import get_random_subreddit [as 别名]
def whoosh(r: praw.Reddit):
print("Looking for unsuspecting victim")
comment_made = False
while not comment_made:
random_sub = r.get_random_subreddit()
print("Searching top submissions of {}".format(random_sub.display_name))
try:
for submission in random_sub.get_hot(limit=10):
flat_comments = praw.helpers.flatten_tree(submission.comments)
for comment in flat_comments:
if any(string in comment.body for string in words_to_monitor):
print("Victim Found!")
comment.reply(random.choice(what_to_say))
print("Comment made to post {} with comment id {}".format(submission.id, comment.id))
comment_made = True
break # Only antagonize our first found victim. Nothing more.
else:
continue
break
else:
continue
break
except (AttributeError, praw.errors.APIException) as e:
print("Error encountered:")
print(e)
print("Moving onto next sub")