gpt4 book ai didi

Python Praw 在 subreddits 中跳过粘性

转载 作者:太空宇宙 更新时间:2023-11-04 08:44:34 24 4
gpt4 key购买 nike

我正在尝试遍历 subreddits,但想忽略顶部的置顶帖子。我能够打印前 5 个帖子,不幸的是包括即时贴。尝试跳过这些的各种 pythonic 方法都失败了。下面是我的代码的两个不同示例。

            subreddit = reddit.subreddit(sub)
for submission in subreddit.hot(limit=5):

# If we haven't replied to this post before
if submission.id not in posts_replied_to:
##FOOD

if subreddit == 'food':

if 'pLEASE SEE' in submission.title:
pass
if "please vote" in submission.title:
pass
else:
print(submission.title)
if re.search("please vote", submission.title, re.IGNORECASE):
pass
else:

print(submission.title)

我注意到文档中有一个粘性标签,但不确定如何使用它。感谢您的帮助。

最佳答案

粘附的提交有一个 sticked 属性,该属性的计算结果为 True。将以下内容添加到您的循环中,您应该可以开始了。

if submission.stickied:
continue

一般来说,我建议检查您正在使用的对象的可用属性,看看是否有可用的东西。请参阅:Determine Available Attributes of an Object

关于Python Praw 在 subreddits 中跳过粘性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41861138/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com